1

In SDL Mix is there a way to halt a specific Mix_Music track? Eg. something like this:

//music1 = the target music track to halt
if(condition)
{
    Mix_Halt(Music1);
}

Thanks.

2 Answers2

1

There is only one Mix_Music track. When you start to play music with Mix_PlayMusic, the previously playing music will automatically be halted (possibly with a fadeout). If you want to explicitly halt the currently playing Mix_Music track, you can use Mix_HaltMusic.

If you want to control sounds concurrently, you should use Mix_Chunk objects instead. These are samples that can be played on multiple channels, which can be controlled individually, e.g.:

Mix_Chunk* chunk1 = Mix_LoadWAV("chunk1.wav");
Mix_Chunk* chunk2 = Mix_LoadWAV("chunk2.wav");

Mix_PlayChannel(1, chunk1, -1); // Play chunk1 on channel 1
Mix_PlayChannel(2, chunk2, -1); // Play chunk2 on channel 2

if (condition)
    // Only halt channel 1, while channel 2 keeps playing
    Mix_HaltChannel(1);

You can find all this information in the documentation.

Meyer
  • 1,662
  • 7
  • 21
  • 20
0

There is a Mix_Pause or Mix_HaltChannel function which pauses specific channels if that's what you're after.

Colin
  • 3,394
  • 1
  • 21
  • 29