We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4216 - Mix_PlayMusic() can't start playing when previously music was paused and re-opened
Summary: Mix_PlayMusic() can't start playing when previously music was paused and re-o...
Status: RESOLVED FIXED
Alias: None
Product: SDL_mixer
Classification: Unclassified
Component: misc (show other bugs)
Version: unspecified
Hardware: All All
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-07-13 20:05 UTC by Vitaly Novichkov
Modified: 2018-08-07 07:31 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vitaly Novichkov 2018-07-13 20:05:02 UTC
Some weeks ago I have found a minor bug:

1) Open any music
2) Start it's playing by Mix_PlayMusic()
3) Pause music by Mix_PauseMusic()
4) Open another music
5) Try to start it by Mix_PlayMusic()
6) Nothing will be played! [The song must be started, but that wasn't happen!!!]
7) Call Mix_ResumeMusic() - and music will begin playing!

I figured out that you forgot to reset the `music_active` flag to SDL_TRUE on re-opening another song. I have fixed it on my fork:

https://github.com/WohlSoft/SDL-Mixer-X/commit/4656707223de4b3bbee6a9729b88d4d2c065387b
Comment 1 Ozkan Sezer 2018-08-01 16:28:51 UTC
That patch seems wrong because it doesn't honor retval.

Correct one should be either this (always setting music_active):

diff --git a/music.c b/music.c
--- a/music.c
+++ b/music.c
@@ -761,6 +761,7 @@ int Mix_FadeInMusicPos(Mix_Music *music,
     retval = music_internal_play(music, loops, position);
     Mix_UnlockAudio();
 
+    music_active = (retval == 0);
     return(retval);
 }
 int Mix_FadeInMusic(Mix_Music *music, int loops, int ms)



... or this (only setting to true if no error):

diff --git a/music.c b/music.c
--- a/music.c
+++ b/music.c
@@ -760,6 +760,9 @@ int Mix_FadeInMusicPos(Mix_Music *music,
     }
     retval = music_internal_play(music, loops, position);
     Mix_UnlockAudio();
+    if (retval == 0) {
+        music_active = SDL_TRUE;
+    }
 
     return(retval);
 }


Can't decide which is better for now.
Comment 2 Ozkan Sezer 2018-08-01 16:48:46 UTC
I think the first choice (always setting music_active to something)
is correct, because music_internal_play() halts the existing music
anyway.

Correct?
Comment 3 Ozkan Sezer 2018-08-07 07:31:29 UTC
Applied this patch:  https://hg.libsdl.org/SDL_mixer/rev/671a669e1065

Closing as fixed.

Note though, this doesn't take into account the issue noted
in https://bugzilla.libsdl.org/show_bug.cgi?id=4221 .