0

好吧,我可以找到许多关于相同或相似问题和答案的问题......但是,没有什么可以帮助我。只有当我不使用属性“controlStyle”作为“MPMovieControlStyleFullscreen”时,“完成”按钮才有效。我试过这个方法。。

    MPMoviePlayerController *mpMoviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"https://dl.dropbox.com/u/14218997/thxq.mp4"]];
    mpMoviePlayerController.controlStyle = MPMovieControlStyleNone;
    [mpMoviePlayerController setUseApplicationAudioSession:NO];
    [mpMoviePlayerController setScalingMode:MPMovieScalingModeAspectFit];
    [mpMoviePlayerController setFullscreen:YES animated:YES];
    [mpMoviePlayerController.view setFrame:CGRectMake(0, 0, 1024, 768)];

    [[globalSingleton paintingView] addSubview:mpMoviePlayerController.view];

    [mpMoviePlayerController prepareToPlay];
    [mpMoviePlayerController play];

    mpMoviePlayerController.controlStyle = MPMovieControlStyleFullscreen;

或者这样..

    MPMoviePlayerController *mp;
    MPMoviePlayerViewController *mpVC = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:@"https://dl.dropbox.com/u/14218997/thxq.mp4"]];
    mp = [mpVC moviePlayer];
    mp.controlStyle = MPMovieControlStyleFullscreen;
    mp.fullscreen = NO;
    mp.useApplicationAudioSession = NO;
    mp.view.frame = CGRectMake(0, 0, 1024, 768);

    [[globalSingleton paintingView] addSubview:mp.view];

([globalSingleton paintingView]只是代表主视图,我已经检查过没有问题。)

请分享你对这个问题的了解。提前谢谢!

4

1 回答 1

3

根据您的代码,在我看来,您的意图是让全屏电影播放器​​接管屏幕。在这种情况下,您可能最好使用 MPMoviePlayerViewController,但您需要使用当前视图控制器将其呈现为模态视图控制器,如下所示:

MPMoviePlayerViewController *movieViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:someVideoURL];
movieViewController.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;

// Self is the UIViewController you are presenting the movie player from.
[self presentMoviePlayerViewControllerAnimated:movieViewController];

在这种情况下,“完成”按钮应该可以正常工作,并关闭模态 MPMoviePlayerViewController

另一方面,如果您对在当前视图层次结构中添加电影的位置更感兴趣,这里是我为实现此目的所做的一个示例:

我还发现将MPMoviePlayerController的 controlStyle 属性设置为MPMovieControlStyleFullscreen具有相同的结果——“完成”按钮没有关闭MPMoviePlayerController. 当我将其更改为 时MPMovieControlStyleDefault,它按预期工作。但是,就我而言,我将MPMoviePlayerController' 的视图作为缩略图大小的子视图添加到当前显示UIViewController的 ' 视图中。我最初将MPMoviePlayerController's controlStyle 设置为MPMovieControlStyleNone. 我UIButton在缩略图大小的电影播放器​​视图顶部有一个自定义,在按钮的操作方法中,我将 controlStyle 更改MPMoviePlayerControllerMPMovieControlStyleDefault,然后调用setFullscreen:animated:哪个动画播放器视图进入全屏模式。然后,点击“完成”按钮正确地动画播放器回到我的缩略图大小的子视图UIViewController中 的观点。这是一个例子:

my 的初始实例化MPMoviePlayerController

// My moviePlayerController is a property
self.moviePlayer = [[MPMoviePlayerController alloc] initWithURL:videoURL];
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
moviePlayer.shouldAutoplay = NO;


// Add the moviePlayer's view as a subview of a my UIViewController's view.
moviePlayer.view.frame = CGRectMake(20, 20, 160, 90);
[self.view addSubview:moviePlayer.view];

注意:我还在我的 moviePlayer 的视图顶部添加了一个自定义 UIButton(用于调用全屏播放),并将它的操作设置为调用以下方法:

- (void)buttonAction:(UIButton *)sender
  {
      self.moviePlayer.controlStyle = MPMovieControlStyleDefault;
      [self.moviePlayer setFullscreen:YES animated:YES];
      [self.moviePlayer play];
  }

注意:我还观察并处理了 MPMoviePlayerWillExitFullscreenNotification,其中我将 controlStyle 设置回 MPMovieControlStyleNone。

于 2012-07-21T23:36:46.093 回答