【问题标题】:Issue while playing video in full screen mode using MPMoviePlayerViewController使用 MPMoviePlayerViewController 以全屏模式播放视频时出现问题
【发布时间】:2023-03-26 14:10:02
【问题描述】:

我在使用MPMoviePlayerViewController 以全屏模式播放视频时遇到问题(在正常模式下完美运行)。

代码:

if (PlayV) {
    self.previewView.hidden=NO;
    self.videoController =[[MPMoviePlayerController alloc] initWithContentURL:self.videoURL];

    [self.videoController.view setFrame:self.previewView .frame];
    self.videoController.view.center=self.playBtn.center;
    [self.previewView addSubview:self.videoController.view];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.videoController];
    self.videoController.scalingMode = MPMovieScalingModeAspectFit;
    self.videoController.controlStyle = MPMovieControlStyleNone;

    [self.videoController play];
}

【问题讨论】:

  • 请改进您的代码格式
  • @objectiveCoder 将您的解决方案发布为答案,而不是评论。 Stackoverflow 不是一个论坛,与您可能使用过的任何其他网站不同,因此请阅读faq

标签: ios mpmovieplayer


【解决方案1】:

我得到了解决方案。在playBtnAction方法中加入这行代码:

- (IBAction)playBtnAction:(id)sender {
    [self.videoController setFullscreen:YES animated:YES]; 
}

然后将这行代码添加到您的videoPlayBackDidFinish 中。

MPMoviePlayerController *player=[notification object];
if ([player respondsToSelector:@selector(setFullscreen:animated:)]) { 
    [player.view removeFromSuperview]; 
}

此代码将检查视频是否处于全屏模式并将其恢复为正常模式。

【讨论】:

    【解决方案2】:
    moviePlayer =  [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:imagepath]]; //moviePlayer declared in .h and set URL
    
    moviePlayer.view.frame = CGRectMake(364, 89, 660, 668); //set custom frame
    moviePlayer.controlStyle = MPMovieControlStyleDefault;
    moviePlayer.shouldAutoplay = YES;
    [self.view addSubview:moviePlayer.view]; //add to view
    [moviePlayer setFullscreen:NO animated:YES];
    

    这可能会对你有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-19
      • 1970-01-01
      • 2014-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多