0

我可以使用 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];

我正在使用上面的代码播放视频。如果我按下 Home Button ,然后回到应用程序,视频就消失了。我只能看到加载中..

4

2 回答 2

5

[_moviePlayer play]当应用程序再次激活时,您应该能够通过调用来重新开始播放。

您可以从 AppDelegate 的方法回调applicationDidBecomeActive,或者执行以下操作:

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

为通知添加观察者(不要忘记稍后将其删除)。

于 2012-07-07T15:35:49.920 回答
0

注册 MPMoviePlayerPlaybackStateDidChangeNotification 通知并检查 _moviePlayer.movi​​ePlayer 属性上的 endPlaybackTime 值

然后在下次显示播放器时将 initialPlaybackTime 设置为上一个结束值

于 2012-07-06T15:27:31.977 回答