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

Re: [pygame] [Pygame] Fading Between Two Songs



Greetings, Urtling. There's a few ways, I think, and maybe more.

1. When you fade the song that's playing, also queue the next song at that time: pygame.mixer.music.queue(). No fuss. The next song will start playing immediately.

2. Tell Pygame to send an event when a song stops playing: pygame.mixer.music.set_event(). As I recall, you have to use a valid Pygame event type, such as something between USEREVENT and NUMEVENTS. Because this passes control to your program, you can employ a programmed delay before the next song.

3. Your game loop can check if the song is playing and start it up if it's not: pygame.mixer.music.get_busy(). Likewise, this supports the option of a programmed delay.

Gumm

On Tue, Jul 6, 2010 at 5:14 PM, Fawkes <fawkesgarde@xxxxxxxxx> wrote:
Hello,

I need some help with using Pygame's music module. Specifically, is
there a way to fade between two songs?

Suppose I have a song playing called via:

pygame.mixer.music.load('song1.ogg')
pygame.mixer.music.play(-1)

I tried to use Pygame's Music Module's fadeout, but that didn't work:

[Song is already playing]

pygame.mixer.music.fadeout(1000)
pygame.mixer.music.load('song2.ogg')
pygame.mixer.music.play(-1)

The music fadeout function seems to block out all input during that
time (Despite comments to the contrary in the documentation). I'd like
to transition smoothly between those songs without blocking the user's
input. Is there a good way to do this?

Thanks in advance.
-Fawkes