Looping music for games --SDL_Mixer

Started by
2 comments, last by samuraicrow 15 years, 3 months ago
How, using SDL_Mixer, would I make it so that a track will play once in its entirety, and then infinitely loop after the "intro" of the song has played seamlessly? There seems to be nothing built in for this, and I can find no such solution on Google. Thanks in advance.
Advertisement
Quote:Original post by Rokkuman
How, using SDL_Mixer, would I make it so that a track will play once in its entirety, and then infinitely loop after the "intro" of the song has played seamlessly? There seems to be nothing built in for this, and I can find no such solution on Google. Thanks in advance.
There was another thread on the exact same topic in this forum at some point in the past, but I don't have a link. You might try searching the forum archives for 'SDL_mixer loop' or something of that sort.

The short answer is that SDL_mixer has no built-in support for this, so you'll have to do it yourself using your own code and the SDL_mixer callbacks. Personally, I haven't had much luck with looping music in SDL_mixer (it seems to 'hitch' intermittently at the loop point - maybe due to rebuffering?), but maybe I've just been doing something wrong...
It was probably my thread and I've come back almost a year and a half later for revenge as I have still not yet figured out how to do what people have been doing in some way, shape, or form for like 30 years.

Although kavendek's belated reply:
Quote:
This thread is kind of old, but in my search for something else, I accidentally found this thread and it piqued my interest.

It seems like the methods of going back and looping from some predetermined point in the music is a much more difficult way of doing this. Wouldn't it be a lot less error prone and simpler to just have two separate music files, one for the intro, and one for the part that loops? You can then make it so that your on-finished callback will just loop the loop-able track, none the wiser that the initial music call actually was playing the intro track. Then all you have to be concerned with is making that one looping track loop well. This could even be generalized to any set of intro/loop music tracks, through some cooked-up naming convention.

Just my two cents!


is certainly an interesting solution. I've thought of this myself, but is there any way to pull this off with NO seams that are caused by anything other than the music itself?
If you don't need to use a streamed file format then it is much easier to loop it. If your music was in .XM format it would loop without effort. Are you using MP3 or OGG? That may be the problem.

This topic is closed to new replies.

Advertisement