I Haz Codes
mixer. |
init() |
|||
mixer. |
music. |
load(" |
filename |
") |
mixer. |
music. |
play() |
Pygame uses a mixer class to allow both sound and music to be played at the same time. As a computer only has one set of speakers, sounds must be mixed together before they are sent to the speaker. Pygame mixer handles the complexity of this code for you.
Some sample code to try –
from pygame import *
mixer.init()
mixer.music.load('hero quest.ogg')
mixer.music.play()
endProgram = False
while not endProgram:
# pygame events
while mixer.music.get_busy():
time.Clock().tick(10)
When playing music in pygame, you should convert your files to ogg. MP3 files tend to be buggy and will not always play.
http://audio.online-convert.com/convert-to-ogg
http://thepythongamebook.com/en:pygame:step010
http://www.pygame.org/docs/ref/music.html
Leave a Reply