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 549 - Mix_HaltMusic doesn't call music finished hook
Summary: Mix_HaltMusic doesn't call music finished hook
Status: ASSIGNED
Alias: None
Product: SDL_mixer
Classification: Unclassified
Component: misc (show other bugs)
Version: 1.2.8
Hardware: x86 Linux
: P2 API change
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
: 550 551 552 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-02-13 06:34 UTC by Alex
Modified: 2012-06-01 03:29 UTC (History)
2 users (show)

See Also:


Attachments
Patch to add this behaviour. (312 bytes, patch)
2009-10-08 02:27 UTC, Ryan C. Gordon
Details | Diff
Patch to call music callback anytime music is stopped (724 bytes, patch)
2009-10-11 00:41 UTC, Sam Lantinga
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alex 2008-02-13 06:34:47 UTC
I don't know if this is a bug or feature, but IMO it would be much more sensible for it to call the hook function. Mix_HaltChannel does call callback functions, so there's confusing difference in behavior.
Comment 1 Alex 2008-02-18 03:11:45 UTC
*** Bug 550 has been marked as a duplicate of this bug. ***
Comment 2 Alex 2008-02-18 03:13:33 UTC
*** Bug 551 has been marked as a duplicate of this bug. ***
Comment 3 Alex 2008-02-18 03:13:50 UTC
*** Bug 552 has been marked as a duplicate of this bug. ***
Comment 4 Sam Lantinga 2009-10-03 02:57:11 UTC
Ryan, can you evaluate this?  Thanks!
Comment 5 Ryan C. Gordon 2009-10-08 02:26:57 UTC
The docs for Mix_HookMusicFinished() say: "This callback is only called if the music finishes naturally."

So, it might break existing programs if we change it to run the callback during Mix_HaltMusic().

Tossing bug to Sam to decide if that's okay.

--ryan.
Comment 6 Ryan C. Gordon 2009-10-08 02:27:57 UTC
Created attachment 401 [details]
Patch to add this behaviour.


This patch will add the behaviour requested here, if you think it's safe to do so.

--ryan.
Comment 7 Ryan C. Gordon 2009-10-09 21:43:44 UTC
Honestly, I'm sort of thinking we should do this and see what breaks.

--ryan.
Comment 8 Sam Lantinga 2009-10-09 22:03:39 UTC
Okay, I remember we added this for Heroes 3, so we should probably check to see if that breaks. ;)
Comment 9 Sam Lantinga 2009-10-11 00:38:16 UTC
I looked into this more closely, and this is a sensible but dangerous change to make.

The right thing to do here is to have both the channel and music callbacks always called when a channel or music stops for any reason, but it should be passed a reason why the sound stopped.

The typical use of the music stopped callback is to pick another song to play.  The assumption is that if you're explicitly halting the music that you have some other action that you are in control of that you want to take place.

If we change this behavior, then suddenly applications will be getting a finished callback when they don't expect it, and this could cause anything from application bugs to crashes.

So, I'm punting this until we do an SDL_mixer API revamp.
Comment 10 Sam Lantinga 2009-10-11 00:41:34 UTC
Created attachment 409 [details]
Patch to call music callback anytime music is stopped

This is a more comprehensive patch that calls the finished hook anytime music stops playing.  If this were applied, we'd also want to change the hook function to take a reason as a parameter, and update the channel finished hook to do the same thing.
Comment 11 Aki Koskinen 2012-05-25 03:08:25 UTC
Waking up a hibernating bug here...

If the behaviour of the lib is not changed as discussed in this bug (i.e. the attached patch won't be applied) would it be appropriate to fix the documentation to reflect the reality? It currently claims that the music finished callback would be called when Mix_HaltMusic() is called but that doesn't happen.

I just spent quite an amount of time believing the documentation and wondering why my callback doesn't get called. I might not be the only one wasting time this way...
Comment 12 Ryan C. Gordon 2012-05-29 21:38:07 UTC
(In reply to comment #11)
> If the behaviour of the lib is not changed as discussed in this bug (i.e. the
> attached patch won't be applied) would it be appropriate to fix the
> documentation to reflect the reality? It currently claims that the music
> finished callback would be called when Mix_HaltMusic() is called but that
> doesn't happen.

Where does it say this?

--ryan.
Comment 13 Aki Koskinen 2012-05-31 02:33:01 UTC
(In reply to comment #12)
> (In reply to comment #11)
> > If the behaviour of the lib is not changed as discussed in this bug (i.e. the
> > attached patch won't be applied) would it be appropriate to fix the
> > documentation to reflect the reality? It currently claims that the music
> > finished callback would be called when Mix_HaltMusic() is called but that
> > doesn't happen.
> 
> Where does it say this?

In http://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer.html#SEC67

[--] Any callback set by Mix_HookMusicFinished will be called when the music stops. [--]

And in http://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer.html#SEC69

[--] This sets up a function to be called when music playback is halted. Any time music stops, the music_finished function will be called. [--]
Comment 14 Ryan C. Gordon 2012-06-01 03:29:54 UTC
Sam, can we update those docs?

--ryan.