2

Consider the following case.

I have two mp3 files that I load with Mix_LoadMUS, therefore obtaining two instances of Mix_Music *. Let's call them m1 and m2.
I play the first track for a while using Mix_PlayMusic:

Mix_PlayMusic(m1, -1);

Then I (let me say) replace the first track with the second one using the second command:

Mix_PlayMusic(m2, -1);

Note: I don't free m1 because I want to use it again in future.
After a while, I decide to play again m1, using exactly the same command shown above.

Here it is the problem.

When I play m1 the second time, I expect it starts from 0 as from the documentation:

Play the loaded music loop times through from start to finish.

Well, it does it. Almost. The problem is that a few milliseconds of the track immediately following the point it was when I stopped it are played for an unknown reason. Then it starts to reproduce the music from the start and that's all.

Am I doing something wrong? It looks like reusing an already existent Mix_Music doesn't work properly.
I mean, it seems that what's in the buffer when the music is stopped is still there and thus is played when I run Mix_PlayMusic the second time. Is this the intended behavior, a bug or something I'm just missing?


As a side note, it works as expected if I free m1 when m2 is played, then I load it again later.

skypjack
  • 49,335
  • 19
  • 95
  • 187
  • So I tried a go at this for a few hours, what I found. It doesnt affect wav files. If you wait for it to finish music with a function hook and do a PlayMusic it works as expected (meaning from the beggining). nor halt nor rewind make this problem go away. Here is a MCVE that reproduces your problem (since you didn't give one.. https://gist.github.com/araml/7191ba537e497cc1ccd7e0199c65bdc6). – aram Apr 15 '18 at 23:41
  • @Aram Thank you very much, I was out of home yesterday and didn't find the time to reply. I confirm that everything works fine with wav and also ogg files and that halt/rewind doesn't solve it. I wrote to the author and he confirms it's probably a bug of the library. He asked me to open an issue to the bugzilla. Can I use your mvce also for that? – skypjack Apr 16 '18 at 05:18
  • @Aram Another note: don't you need a `Mix_Init` in your mvce to request to load mp3 support stuff? – skypjack Apr 16 '18 at 05:20
  • I think in my local copy I was using Mix_Init and yes you can use it to file the bug. – aram Apr 16 '18 at 05:33
  • @Aram [Here](https://bugzilla.libsdl.org/show_bug.cgi?id=4138) it is. Thank you. Let's see if it's confirmed. – skypjack Apr 16 '18 at 06:58
  • I'm seeing this same issue, but with WAV files. I've updated the [bug report](https://github.com/libsdl-org/SDL_mixer/issues/245) with what I know so far. – Rusty Moyher Jul 17 '21 at 22:33

0 Answers0