Detect when the MPMoviePlayerController is paused or stopped
There are two symptoms I am experiencing:
1)开发者_JS百科 when I call [ourMovie release]
in my movieFinished:
method below, I am told I am releasing something already released .. isn’t the [sentNotification object]
passed to –movieFinished:
a copy and therefore something I have to release ??
2) totally unrelated to (1) is that when add a NSNotification observer for MPMoviePlayerPlaybackDidFinishNotification
, the movie does not show up. No detectable error, just a no-show ?? My goal here is to detect when the user pauses or stops the playback and then pushes the Home button to send my app to the background. When the app returns to the foreground, I want to continue the movie where the user left it when he pushed the pause or stop button .. not start from scratch as my app does now.
Before I proceed, I do have the following in my AppDelegate:
[notificationCenter addObserver:self
selector:@selector(pauseApp)
name:@"UIApplicationDidEnterBackgroundNotification"
object:ourApp];
FYI: my –pauseApp eventually calls [ourMovie pause]
In my –playVideo: method I have
[notificationCenter addObserver:self
selector:@selector(movieFinished:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:ourMovie];
[notificationCenter addObserver:self
selector:@selector(pauseDownload)
name:@"MPMoviePlayerPlaybackStateDidChangeNotification"
object:ourMovie];
and for my –movieFinished method I have
- (void )movieFinished:(NSNotification *)sentNotification
{
NSObject *theNotifyObject = [sentNotification object];
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
if ( [theNotifyObject isKindOfClass:[MPMoviePlayerController class]] )
{
MPMoviePlayerController *ourMovie = (MPMoviePlayerController *)theNotifyObject;
[notificationCenter removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:ourMovie];
[notificationCenter removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:ourMovie];
[ourMovie pause];
[ourMovie stop];
[ourMovie release]; // release what we don't own ???
}
}
1) No, you don't have to release ourMovie
. You are not copying anything, you are just passing an object as an argument to a method, hence referencing the same place in memory. So if your previous memory management was correct when creating the object, you don't have to do anything at this point.
2) If you want the video to play from the same place in time, then why are you calling stop
after you call pause
on ourMovie
?
This a citation from Apple documentation on MPMediaPlayBack's stop
method: "This method stops playback of the current item and resets the playhead to the start of the item."
精彩评论