MPMoviePlayerController sends "end of movie reached" when URL is changed
Asked Answered
P

2

9

I'm trying to get a notification from a MPMoviePlayerController when the movie has reached its end. I'm running the player in embedded mode with a local file.

Like the docs suggest, I registered for MPMoviePlayerPlaybackDidFinishNotification and check if the MPMovieFinishReason key contains the intValue of MPMovieFinishReasonPlaybackEnded. That's working fine.

But I get the same notification with MPMovieFinishReasonPlaybackEnded when I switch the movie using the contentURL property before it has actually reached its end. So I tried this solution and checked if endPlaybackTime == -1, but that's true in both cases.

The only workaround I found so far is to remove the observer before changing contentURL and then adding it again, but I think there must be a more elegant solution?

Philous answered 15/11, 2011 at 15:19 Comment(2)
Are you doing that on background?Coaster
Do you mean on a background thread? NoPhilous
S
0

It appears to work consistently to simply removeObserver, stop playback/change the Url, then addObserver once more.

Silsbye answered 8/7, 2012 at 7:24 Comment(1)
Right, it still looks like there is no better solution. I'll accept this answer, although this has been mentioned in the question already ;)Philous
M
0

So, per the documentation, your observed behavior seems to be the correct behavior. I think your solution to quit getting notifications might be a good one. Yeah, it's a little hacky, but it seems like it would work.

Alternatively, what about storing the URL of the movie(s) you're playing and comparing against [moviePlayer contentURL]? You might have to do some timer acrobatics and have a currentMovieURL and a previousMovieURL, but that ought to provide a good way to compare if the movie that ended is the movie you expected to end.

Alternatively to that, what about setting 2 variables: movieStartTime and expectedMovieDuration? Then, you can compare [NSDate date] to [movieStartTime dateByAddingTimeInterval:expectedMovieDuration] and see if it's way off.

Micronucleus answered 4/5, 2012 at 19:51 Comment(0)
S
0

It appears to work consistently to simply removeObserver, stop playback/change the Url, then addObserver once more.

Silsbye answered 8/7, 2012 at 7:24 Comment(1)
Right, it still looks like there is no better solution. I'll accept this answer, although this has been mentioned in the question already ;)Philous

© 2022 - 2024 — McMap. All rights reserved.