# Changing music tracks in SDL\_Mixer

**URL:** <https://discourse.libsdl.org/t/changing-music-tracks-in-sdl-mixer/14922>\
**Category:** SDL Development\
**Created:** [October 27, 2007, 9:14pm UTC](https://discourse.libsdl.org/t/changing-music-tracks-in-sdl-mixer/14922 "2007-10-27T21:14:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mason\_Wheeler](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/b9bd4f/32.png) [@Mason\_Wheeler](https://discourse.libsdl.org/u/Mason_Wheeler)\
**Post date:** [October 27, 2007, 9:14pm UTC](https://discourse.libsdl.org/t/changing-music-tracks-in-sdl-mixer/14922/1 "2007-10-27T21:14:08Z")

</div>

I’m trying to use SDL\_Mixer to handle audio in a game I’m writing. SFX work  
fine, but unfortunately, it’s being quite ornery on the subject of  
soundtrack management. I can’t get it to switch tracks. I load various  
songs into an array during initialization with Mix\_LoadMUS, and the first  
one I play works just fine. But after that, if I try to switch tracks, no  
other song will play. I call Mix\_HaltMusic, then Mix\_PlayMusic with the  
other song’s pointer, then Mix\_HookMusicFinished. No music actually plays,  
but after the appropriate amount of time, the callback routine does get  
called, as if it had been playing silently all along. After this, I’m able  
to play the original song again with no trouble, but switching to other  
songs just doesn’t work.

Does anyone know what the step is I’m missing? Such an all-around  
well-designed library simply _can’t_ have fallen flat on its face on this  
one crucial feature, so I must be missing a step somewhere. Can anyone tell  
me what it is?

Mason–  
View this message in context: [http://www.nabble.com/Changing-music-tracks-in-SDL\_Mixer-tf4704537.html#a13447451](http://www.nabble.com/Changing-music-tracks-in-SDL_Mixer-tf4704537.html#a13447451)  
Sent from the SDL mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Mason\_Wheeler](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/b9bd4f/32.png) [@Mason\_Wheeler](https://discourse.libsdl.org/u/Mason_Wheeler)\
**Post date:** [October 27, 2007, 9:38pm UTC](https://discourse.libsdl.org/t/changing-music-tracks-in-sdl-mixer/14922/3 "2007-10-27T21:38:44Z")

</div>

Oh, all right. I’d heard that file format and other technical details don’t  
matter with SDL because it takes care of all that stuff for you, but the  
songs are all in MIDI format, and I’m running under Windows XP.

Mason

Jesse P. wrote:\>

> Hi,
> 
> I would be helpful to us if you stated what music file format you are  
> using…
> 
> I personally like the “_.MOD" music format, but last I checked it was  
> not 100% in SDL\_Mixer.  
> I am currently using Ogg Vorbis "_.OGG” music file format which is  
> similar to MP3.
> 
> Jesse “JeZ+Lee”  
> Silent Hero Productions(R)  
> Video Game Design Studio  
> [http://www.SilentHeroProductions.com](http://www.SilentHeroProductions.com)

–  
View this message in context: [http://www.nabble.com/Changing-music-tracks-in-SDL\_Mixer-tf4704537.html#a13447696](http://www.nabble.com/Changing-music-tracks-in-SDL_Mixer-tf4704537.html#a13447696)  
Sent from the SDL mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Bill\_Kendrick](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/b/df788c/32.png) [@Bill\_Kendrick](https://discourse.libsdl.org/u/Bill_Kendrick)\
**Post date:** [October 28, 2007, 7:23am UTC](https://discourse.libsdl.org/t/changing-music-tracks-in-sdl-mixer/14922/4 "2007-10-28T07:23:15Z")

</div>

Keep in mind that SDL is typically acting as an abstraction layer for OS  
APIs or other libraries, so it could be whatever MIDI stuff SDL\_Mixer is  
using is falling flat on its face.

Out of curiosity, have you thrown MP3, Ogg Vorbis or MOD files at it, to  
see if it fails in the same way?

-bill!  
(and I think that’s all I can offer as help for this problem 😉 )On Sat, Oct 27, 2007 at 02:38:44PM -0700, masonwheeler wrote:

> Oh, all right. I’d heard that file format and other technical details don’t  
> matter with SDL because it takes care of all that stuff for you, but the  
> songs are all in MIDI format, and I’m running under Windows XP.

---

<div class="post-metadata">

**Author:** ![Sam\_Crow](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@Sam\_Crow](https://discourse.libsdl.org/u/Sam_Crow)\
**Post date:** [November 2, 2007, 5:20pm UTC](https://discourse.libsdl.org/t/changing-music-tracks-in-sdl-mixer/14922/5 "2007-11-02T17:20:05Z")

</div>

You might consider looking up RW\_ops to store your files in memory and load them  
from memory instead of loading them all in with Mix\_LoadMus.

---

<div class="post-metadata">

**Author:** ![Sam\_Crow](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@Sam\_Crow](https://discourse.libsdl.org/u/Sam_Crow)\
**Post date:** [November 2, 2007, 5:24pm UTC](https://discourse.libsdl.org/t/changing-music-tracks-in-sdl-mixer/14922/6 "2007-11-02T17:24:16Z")

</div>

Sam Crow \<samuraileumas [yahoo.com](http://yahoo.com)\> writes:

> You might consider looking up RW\_ops to store your files in memory and load  
> them from memory instead of loading them all in with Mix\_LoadMus.

Never mind, RW\_ops only works with samples.
