2012-07-06 64 views
0

我能够使用MPMoviePlayerViewController播放视频文件,一切工作正常。但是,如果我按Home按钮,现在打开应用程序,视频将从超级视图中删除。我知道如何获取通知。你能告诉我如何恢复相同的视频?在MPMoviePlayerViewController中恢复视频

NSString* filePath = [[NSBundle mainBundle] pathForResource:@"adv" ofType:@"mp4"]; 
NSURL* url = [NSURL fileURLWithPath:filePath]; 

_moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url]; 
[_moviePlayer.view setFrame:self.view.bounds]; 
[self.view addSubview:_moviePlayer.view]; 

我正在使用上面的代码播放视频。如果我按下主页按钮,然后回到应用程序,视频就消失了。我能看到的只有中..为MPMoviePlayerPlaybackStateDidChangeNotification通知

+0

请检查我更新的问题 – Perseus 2012-07-06 15:22:49

回答

0

登记和检查_moviePlayer.movi​​ePlayer财产endPlaybackTime值

那么球员显示下一次设置initialPlaybackTime以前的终值

+0

当应用程序启动时,MPMoviePlayerPlaybackStateDidChangeNotification正在被调用。当我按home键并再次打开应用程序时,它不会被调用 – Perseus 2012-07-06 15:59:31

5

当应用程序再次处于活动状态时,您应该可以通过调用[_moviePlayer play]重新开始播放。

你既可以调用从AppDelegate中的applicationDidBecomeActive方法背部,或做类似:

[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidBecomeActiveNotification object:[UIApplication sharedApplication] queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) { 
    [_moviePlayer play]; 
}]; 

添加一个观察员通知(不要忘了在以后进行删除)。

相关问题