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

Re: [pygame] Using multiple music loops



On Mon, 24 Jan 2005, Dave Mikesell wrote:

> I have four short music loops I'd like to use as background music for my
> game.  I'd like to continually loop through all four, playing each one a
> dozen times or so, then move to the next one, etc.

well, i hope you already found you way around the documentation to Sound
and Channel and/or the mixer.music module .. i've never needed that sort 
of stuff myself (am looping videos and switching videos tho) but seems 
simple enough

pygame.mixer.music provides a queue mechanism that might suite you. it 
seems to deal with one file at a time, and streams them instead of 
decoding all at the beginning, so if your loops are long and memory use is
a concern that seems right: 
http://www.pygame.org/docs/ref/pygame_mixer_music.html .. there's also an 
end event system that'll tell you when music stops

but if you have short loops that fit well in the memory and need finer 
control, it seems that Sound.play which returns a Channel (as documented 
in http://www.pygame.org/docs/ref/Sound.html#play) would do - there you 
can either query the channel busyness to know if the previous looping has 
stopped, or which is probably nicer, use end events (note that they 
behave differently than mixer.music end events)
http://www.pygame.org/docs/ref/Channel.html#set_endevent

good luck in using whatever you choose, and do report back experiences.. 

~Toni