Pregunta

I want to play multiple MP3 files in SDL. Using SDL_Mixer, I am able to play one MP3 file.

Mix_Music *music = Mix_LoadMUS("music.mp3");

Mix_PlayMusic(music, 0);

But when I am trying to play another MP3 along with first one, the first one stops and it plays the 2nd one. Can any one help on this?

¿Fue útil?

Solución

SDL_mixer is meant to be a super-simple audio library; a single music track is one of its limitations.

You could play the music as multiple sound effects. There are a few downsides though:

  • You'll have to manage pausing/volume/looping yourself, by keeping track of the channels used to play the sounds. Not too difficult, but it's code you have to write.
  • The sounds won't be streamed, so all your music tracks will be decoded and loaded into RAM uncompressed. These days uncompressed audio isn't that bad - to calculate uncompressed size, simply multiply num_channels * sample_rate * bit_rate * duration_in_seconds, which works out to be 2 * 44100 * 2 * 60 or 10584000 or ~10mb per minute of stereo, 44.1kHz 16-bit (i.e. 2-byte) audio. It's something to watch out for in embedded or low-end systems.

Alternately, you can use a more advanced audio library that supports multiple music channels.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top