[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

RE: [pygame] pygame.init before pygame.mixer.init?



I did a little more testing:

OS: Windows XP
Pygame: I installed v1.7.1 for Win32 and Python 2.5
(http://www.pygame.org/ftp/pygame-1.7.1release.win32-py2.5.exe)

I've reproduced the problem on one other WinXP machine with the same
Pygame release, but the problem doesn't occur on my WinXP machine at
home (the sound plays just fine without pygame.mixer.init).

I've been able to determine that pygame.mixer.get_busy() isn't failing,
simply by replacing "pass" with print "Hello".

Calling pygame.mixer.pre_init() instead of pygame.mixer.init doesn't get
play any sound.

*But* sound will play without pygame.mixer.init if I call
pygame.display.set_mode AND put a time delay between loading the sound
and playing it:

------------------------------------------------------
import pygame

pygame.init()
screen = pygame.display.set_mode((500,500)) 

sound = pygame.mixer.Sound("dog.wav")
pygame.time.delay(1000)
sound.play()
while pygame.mixer.get_busy():
	pass
------------------------------------------------------

A few questions this brings up:
* Why does setting the display make a difference, and why does this fix
the problem of having to call pygame.mixer.init first?
* Why does it take too long to load the sound, such that it won't play
if I call it immediately? And why does calling pygame.mixer.init first
make this problem go away?

-- Clare Richardson

-----Original Message-----
From: owner-pygame-users@xxxxxxxx [mailto:owner-pygame-users@xxxxxxxx]
On Behalf Of Clare Richardson
Sent: Wednesday, October 10, 2007 2:55 PM
To: pygame-users@xxxxxxxx
Subject: [pygame] pygame.init before pygame.mixer.init?

I writing a program to simply play one sound (see below for the code),
and came across some interesting behavior.  If I call pygame.init()
before pygame.mixer.init(), I don't hear any sound playing.  However if
I call pygame.init *after* pygame.mixer.init (as below), the sound will
play.

Is this a known behavior?  What's causing the problem?  I understand
that I don't need pygame.init to just play a sound, but I don't think it
should matter if I call it.

Thanks!
Clare Richardson

-------------------------------------------

import pygame

pygame.mixer.init()
pygame.init()

sound = pygame.mixer.Sound("bark.wav")
sound.play()

while pygame.mixer.get_busy():
    pass

pygame.mixer.quit()