The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
an SDL_Event when a Mix_Music track has completed?
wazoo


Joined: 17 Jun 2010
Posts: 4
Hi everyone,

Amped (pun intended) about getting back into some work using SDL2.

Apologies in advance if I missed it in the documentation, but I was trying to find out if SDL_Mixer triggers an SDL_Event of some kind when a music / sound effect has completed playing.

thanks!
Naith


Joined: 03 Jul 2014
Posts: 158
When it comes to music, there's a callback function named Mix_HookMusicFinished, that you pass a function to, and that function will be called when the music playback has halted. I'm not sure that a music playback is specified as halted when it has finished playing though. It might be that the music playback is only specified as halted whenever the user halts it manually.
If it doesn't work the way you intented, there also a function named Mix_PlayingMusic that returns 1 as long as a music playback is occuring.
https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_69.html#SEC69
https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_71.html#SEC71

When it comes to sounds, there's a callback function named Mix_ChannelFinished which you can use for this purpose, that you pass the channel that you want to check and it will return true when that channel has stopped playing.
https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_37.html#SEC37
most excellent
wazoo


Joined: 17 Jun 2010
Posts: 4
Thanks @Naith for taking the time to respond.

That's EXACTLY what I'm looking for -- trying to time how long to display a splash screen with some audio ditty in the background.

many thanks!