How to stop Video download in MPMoviePlayerController
I have a requirement where I have to play a video file which is available in remote location.
I am passing the URL to MPMoviePlayerController instance and called the method play.
Now, the movie is downloading. I have clicked on the "Done" button before the movie loads completely and came back to the rootview.
MPMoviePlayerPlaybackDidFinishNotification notification got called. I have stopped the video and released the player. Here is the code
- (void)movieDidFinish:(NSNotification *)aNotifciation
{
[self.moviePlayer stop];
[self removeActivityIndicatorView];
[self.tableView reloadData];
[[NSNotificationCenter defaultCenter] removeObs开发者_Go百科erver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[moviePlayer release];
moviePlayer = nil;
}
But, still the video is loading in the background and iam able to hear the audio also.
This must not happen.
Can anyone give the solution for this?
[movieplayer stop];
movieplayer.initialPlaybackTime = -1.0;
[movieplayer release];
Setting initial playbacktime to -1 should solve your problem.
You to register for an NSNotification that the MPMoviePlayerController sends out when it finishes. Here is an example:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
A good place to put that is inside "viewDidLoad" of your main ViewController class.
Then inside your method "movieFinishedCallback:" (which gets an NSNotification object passed in as an argument, which you can use to find our more detail about the kind of finishing that happened if you like) you simply dismiss the movieplayercontroller
精彩评论