我有一个mpMoviePlayerViewController,可以从远程服务器流式传输视频。这一切都运行良好,但我注意到,如果我将应用程序发送到后台(通过按主页按钮),当我重新打开它时,mpMoviePlayerViewController停止播放并消失。
这是我的代码:
-(void)playVideo:(NSURL *)url{
mpViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
if (mpViewController){
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(myMovieFinishedCallback:)
name: MPMoviePlayerPlaybackDidFinishNotification
object: mpViewController.moviePlayer];
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(myMoviePreloadCallback:)
name: MPMoviePlayerLoadStateDidChangeNotification
object: mpViewController.moviePlayer];
}
}
-(void) myMoviePreloadCallback: (NSNotification*) aNotification{
[self performSelectorOnMainThread:@selector(myMoviePreloadCallbackMainThread) withObject:nil waitUntilDone:NO];
}
-(void)myMoviePreloadCallbackMainThread{
[[NSNotificationCenter defaultCenter]
removeObserver: self
name: MPMoviePlayerLoadStateDidChangeNotification
object: mpViewController.moviePlayer];
[self presentMoviePlayerViewControllerAnimated:mpViewController];
[mpViewController.moviePlayer play];
}
-(void) myMovieFinishedCallback: (NSNotification*) aNotification
{
[[NSNotificationCenter defaultCenter]
removeObserver: self
name: MPMoviePlayerPlaybackDidFinishNotification
object: mpViewController.moviePlayer];
[mpViewController.moviePlayer stop];
[self dismissMoviePlayerViewControllerAnimated];
[mpViewController release];
}
有没有办法让玩家从停止的地方继续玩?