Hello,
This is probably a stupid question, but I am unable to find an answer in
the documentation. I am having a problem when stopping / restarting
Pygame Mixer. I have the following test code:
import pygame
for x in range(10):
print("Starting iteration " + str(x))
print("Initializing mixer")
pygame.mixer.init()
print("Loading sound")
sound = pygame.mixer.Sound("foo.wav")
print("Finding free channel")
channel = pygame.mixer.find_channel(True)
print("Channel object: " + str(channel))
print("Setting volume")
channel.set_volume(0.7)
print("Playing sound")
channel.play(sound)
print("Quitting mixer\n\n")
pygame.mixer.quit()
Note that you must have a .wav file 'foo.wav' in the same directory that
you are running this from.
I would expect this code to play the sound 10 times, then quit.
However, it hangs at the channel.set_volume line on the second
iteration. Ctrl C doesn't quit; you have to do a kill <pid> to end it.
Any ideas what I am doing wrong? I need to have some way to unload and
reload the mixer (to allow configuration changes to take effect), but
once I have quit and restarted, I can't seem to change volume on a channel.
I appreciate all suggestions.
Cheers