Detect end of sound playing with SDL_mixer

Hi there,

I’ve never played that much with SDL_mixer or mostly to do basic things. For now I’m trying to figure out a simple way to detect that all sounds have been played entirely.

For example, let say I open two sounds which are 3 seconds and 5 seconds respectively.

If I start playing them using Mix_PlayChannel I can specify a channel, but I’ve always used -1 because I didn’t care that much. I must say that I have a very bare knowledges about use of channels. What will be the easiest way to know when those sounds finished playing? Using Mix_Playing?

What is the usual way of using them? Like having a channel for sounds effects? One for user interaction? One for gameplay?

I’m also trying to understand when to use channels and groups.

Any help is appreciated.


I would stick to using -1 to let Mix_PlayChannel choose a channel for you. I guess it chooses the first free channel it can find. You’re unlikely to need to use channel groups, and there’s no use to reserving channels for UI and game. Channels are just there to allow more than one sound to play at the same time.

If you really want to be notified of when a sound finishes then Mix_ChannelFinished works well. This can be useful for when you want to change the panning or volume of a sound you played earlier because the sound is moving. You’d only want to apply the change to the channel if it’s still playing and a new sound isn’t playing in its place.