music in SDL

Started by
1 comment, last by samuraicrow 15 years, 9 months ago
Ok so i have been able to get wav, mid and mp3 files to play with SDL_Mixer so people talking about needing extra stuff to do this... i don't know what your talking about because its all worked for me. But now i am thinking that if it can read mp3 files then i was thinking instead of putting music in the game just put the folder and let the user add songs to it and it would play these songs. I know how to go through files in a directory and i would just go through them and load them in an array of songs. My big question with this is though how do i loop through and play 1 song after another while the game is going on. If i make a while loop that loops through all the files in the directory and plays each song and put it before the game that loop will have to finish before the game is even played. Do i have to do something like create a new thread that would be the function that loops through the music directory and plays the files in it and have that thread run while the game is running?
Advertisement
There are many ways to accomplish this. It will really depend on how you want to manage a playlist in your application and your knowledge of the APIs you are using. It could be accomplished with callbacks on song completion, using a different thread, timers etc. For example, creating a timer the same length as a song could make it so that you could change to the next song each time a song completes.
Evillive2
The SDL_mixer documentation lists a callback function that can set a semaphore so that another thread can detect when the music is done playing. Don't call the SDL_mixer functions directly from this callback though.

This topic is closed to new replies.

Advertisement