My intention is to have two music tracks, which are similar in nature, fade between each other at various times. When such a fade occurs, one music track should fade from full volume to muted in a short period of time, and, simultaneously, the other track should fade from 0 to 100 and continue playing from there. They must be able to do this dynamically at any time - when a certain action occurs, the fade will occur and the new track will start playing at the same time index that the other one left off at.

This might be plausible by either using volume manipulation or by starting and stopping the music (however, it appears that only a "fadeout" option exists, and there is a lack of a "fadein" option). How can I do this? What is the best method, if any, that exists? If it is impossible using Pygame, alternatives to Pygame are acceptable.

  • \$\begingroup\$ Isn't this a cross-post? \$\endgroup\$
    – pradyunsg
    Mar 4, 2014 at 9:49
  • \$\begingroup\$ @Schoolboy Yes, I did so before I knew that was bad, got away with it, and had it work out rather usefully. All the answers on both sites contributed into me finally solving my problem, so it worked out great. \$\endgroup\$ Mar 4, 2014 at 14:35

2 Answers 2


There is a "fadein" option, it just isn't a function. From the pygame.mixer.Sound documentation:


begin sound playback

play(loops=0, maxtime=0, fade_ms=0) -> Channel


The fade_ms argument will make the sound start playing at 0 volume and fade up to full volume over the time given. The sample may end before the fade-in is complete.

  • \$\begingroup\$ Is it also possible to start from a given manual position using this method? \$\endgroup\$ Sep 11, 2013 at 13:19
  • \$\begingroup\$ You mean in the middle of a track? I suppose not. The only way is to pause and then play, which is not really what you're after. \$\endgroup\$
    – bradur
    Sep 11, 2013 at 15:10

There is no easy method with pygame.

pygame uses sdl_mixer and shares its limitations. sdl_mixer only supports one streamed, music channel. You could use sound effects instead and manage your own sound samples and channels, but it's a lot of work:

  • Track the progress of each piece of music, including the channel it was played on
  • Without streaming, you have to preload the entire music file into memory. It's a lot because we're talking about uncompressed audio, you're looking at many 10s of MB per minute, depending on sampling rate and bit depth.

So really, you're rolling a crossfade library from scratch.

If you limit your requirements so that you crossfade only at the end/start of tracks, you could create a transition music, and play music1, transition, music2 in that order. It's still annoying to do though.

For more details see this thread: http://forums.indiegamer.com/showthread.php?12641-Cross-fading-with-SDL_mixer

  • \$\begingroup\$ Unfortunately, there is no "start" or "end" to the pieces - they must loop indefinitely, and when one piece fades in, it must resume at the same place that the other piece stopped at, making a seamless transition. \$\endgroup\$ Sep 11, 2013 at 13:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .