1

我想播放此 URL 的视频http://www.youtube.com/watch?v=JPUWNcGDyvM&feature=player_embedded我上次暂停的地方...我可以播放视频但是当我离开此页面并返回查看这个视频将从之前开始。但我想在我上次暂停的地方继续播放这个视频。代码..

- (void)viewDidLoad
{   
 player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:[NSString    stringWithFormat:@"%@video.mp4",urlVideo]]];   
[[NSNotificationCenter defaultCenter]
 addObserver:self
 selector:@selector(movieFinishedCallback:)
 name:MPMoviePlayerPlaybackDidFinishNotification
 object:player];
//---play movie---
[player prepareToPlay];
[player pause];
player.view.frame = CGRectMake(0, 0, 320, 367);
[self.view addSubview:player.view];   
[[NSNotificationCenter defaultCenter]
 addObserver:self
 selector:@selector(movieFinishedCallback:)
 name:MPMoviePlayerPlaybackDidFinishNotification
 object:player];
[super viewDidLoad];
}

我的 movieFinishedCallbackm 方法是:-

- (void) movieFinishedCallback:(NSNotification*) aNotification {
player = [aNotification object];
[[NSNotificationCenter defaultCenter]
 removeObserver:self
 name:MPMoviePlayerPlaybackDidFinishNotification
 object:player];
}
4

1 回答 1

1

使用 MPMoviePlayerController 你可以实现 MPMediaPlayback 协议,所以在你的播放器上,你可以发送一个暂停消息:

[myMoviePlayer pause];

使用 viewWillDisappear 或 viewDidDisappear 暂停视频,使用 viewWillAppear 或 viewdidAppear 继续播放。

- (void)viewWillAppear:(BOOL)animated
{
    [myMoviePlayer play];
}

- (void)viewWillDisappear:(BOOL)animated
{
   [myMoviePlayer pause];
}
于 2012-06-25T08:53:28.323 回答