[Tutor] Sound problems
Tim Goddard
timgoddardsemail at gmail.com
Thu Dec 10 06:30:21 CET 2009
I'm still learning, and this may be better served on a pygame mailing
list but I thought I'd try here first.
I'm following the python programming for absolute beginners which uses
livewires and pygame to do some simple games. My difficulty comes
from not using the module versions used in the book and using the
latest online offerings.
The book creates a simple program to play music and sound in a console
environment.
initially the code was (shortened for brevity):
from livewires import games
# load a sound file
missile = games.load_sound("missile.wav")
#load the music file
games.load_music("theme.mid")
choice == None
while choice != "0":
print """
1 - play missile sound
2 - play music
"""
choice = raw_input("Choose your selection: ")
if choice == "1":
missile.play()
elif choice == "2":
games.play_music()
Which gives an error because the load_music is not part of the latest
games.py module. So after reading through games.py I discovered that
most of it is a pass through to pygames. Also the sound does not
play.
My modified code which plays music but still not sound is:
from livewires import games
# If I don't keep the above line, I get an error that pygame.mixer is
not initialized properly
import pygame
# load a sound file
missile = pygame.mixer.Sound('pickup.wav')
# load the music file
pygame.mixer.music.load("theme.mid")
<menu code>
if choice == "1":
missile.play(3) # loop .wav three times.
print "Playing missile sound"
elif choice == "2":
pygame.mixer.music.play()
print "Playing theme music"
My question is why won't the sound play in the console? When I use
the same code in a program with a screen, it plays normally.
Thanks in advance!
More information about the Tutor
mailing list