0

我正在 iphone 应用程序中播放视频,我希望当单击完成按钮时,播放器应该从播放位置移回原始视图。

我正在使用以下代码

  viewDidLoad(){
     [self play];
  }

  -(void)play{
    NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"3idiots.mov" ofType:nil];
    NSURL    *url    = [NSURL fileURLWithPath:urlStr];
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
    [self.view addSubview:moviePlayer.view];
    moviePlayer.view.frame = CGRectMake(0, 0, 1024, 768);  
    [moviePlayer play];
  }
4

1 回答 1

3

您应该将此通知称为:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doneButtonClicked) name: MPMoviePlayerWillExitFullscreenNotification object:nil];

试试这个(我是为 iPad 做的):

self.player = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doneButtonClicked) name:MPMoviePlayerWillExitFullscreenNotification object:nil];

self.player.view.frame = CGRectMake(0, 0, 1024, 748);
[self.view addSubview:self.player.view];
[self.player setFullscreen:YES animated:YES];
[self.player play];

当完成按钮点击:

-(void)doneButtonClicked
{
    [self.player stop];
    [self.player.view removeFromSuperview];
    [self.navigationController popViewControllerAnimated:YES];//no need this if you are opening the player in same screen;
}
于 2012-08-16T06:12:02.853 回答