首页 文章

在iOS6中进入全屏后,MPMoviePlayerController会中断/停止

提问于
浏览
26

我有 MPMoviewPlayerViewController 嵌入 UIView 对象 . 当我在嵌入模式下启动播放器时,一切正常并且符合预期 . 如果用户然后点击全屏切换(或者如果我使用 setFullscreen:animated 以编程方式更改为全屏),则播放器全屏显示,电影播放另一秒钟,之后屏幕变黑,只显示“正在加载...”消息 .

此行为仅在使用iOS 6(也是iPad 6.0模拟器)时出现,在运行iOS 5的设备上,一切都按预期工作 .

电影源是应用程序包中的本地文件 .

播放和进入全屏时,调试输出如下:

2012-09-26 15:24:48.251 [39895:c07] [MPAVController] Autoplay: Disabling autoplay for pause
2012-09-26 15:24:48.252 [39895:c07] [MPAVController] Autoplay: Disabling autoplay
2012-09-26 15:24:48.262 [39895:c07] [MPAVController] Autoplay: Enabling autoplay
2012-09-26 15:24:48.265 [39895:c07] [MPAVController] Autoplay: Likely to keep up or full buffer: 0
2012-09-26 15:24:48.266 [39895:c07] [MPAVController] Autoplay: Skipping autoplay, not enough buffered to keep up.
2012-09-26 15:24:48.267 [39895:c07] [MPAVController] Autoplay: Likely to keep up or full buffer: 0
2012-09-26 15:24:48.268 [39895:c07] [MPAVController] Autoplay: Skipping autoplay, not enough buffered to keep up.
2012-09-26 15:24:48.276 [39895:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 0, on player: 1)
2012-09-26 15:24:48.286 [39895:c07] [MPCloudAssetDownloadController] Prioritization requested for media item ID: 0
2012-09-26 15:24:48.938 [39895:c07] [MPAVController] Autoplay: Enabling autoplay
2012-09-26 15:24:48.940 [39895:c07] [MPAVController] Autoplay: Enabling autoplay
2012-09-26 15:24:48.954 [39895:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 0, on player: 1)
2012-09-26 15:24:49.006 [39895:c07] [MPAVController] Autoplay: Enabling autoplay
2012-09-26 15:24:49.012 [39895:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 0, on player: 1)

有人知道为什么玩家停止工作?

Edit: 添加了example project on github

11 回答

  • 45

    您是否在 viewWillDisappear:viewDidDisappear: 停止了视频?当视频在iOS 6上进入全屏时会调用这些方法,但在任何早期的iOS版本上都不会调用这些方法(对于此"bug",在Open Radar中为report has been filed) . 我在类似的问题上发布了this temporary solution

    在修复错误之前我的临时解决方案是检查 viewWillDisappear: 和/或 viewDidDisappear: 中玩家的 fullscreen 布尔值 . 如果它返回 YES ,则电影正在进入全屏模式,您应该避免做任何可能会中断它的事情 .

  • 0

    我用不同的方法解决了这个问题 . 由于问题的主要原因是iOS 6调用viewWillDisappear:和/或viewDidDisappear:方法 . 我想也许iOS也调用了MPMoviePlayerViewController的相同方法 . 所以我为MPMoviePlayerViewController创建了一个Category,并实现了viewWillDisappear:和/或viewDidDisappear:方法 . 有趣的是它有效 . (顺便说一下苹果不推荐)

    这是代码;

    Header (MPMoviePlayerViewController_FullscreenFix.h)

    #import <MediaPlayer/MediaPlayer.h>
    
    @interface MPMoviePlayerViewController (MPMoviePlayerViewController_FullscreenFix)
    - (void)viewDidDisappear:(BOOL)animated;
    - (void)viewWillDisappear:(BOOL)animated;
    @end
    

    Implementation (MPMoviePlayerViewController_FullscreenFix.m)

    #import "MPMoviePlayerViewController_FullscreenFix.h"
    
    @implementation MPMoviePlayerViewController (MPMoviePlayerViewController_FullscreenFix)
    
    -(void)viewDidDisappear:(BOOL)animated
    {
        [super viewDidDisappear:animated];
    }
    
    - (void)viewWillDisappear:(BOOL)animated{
        [super viewWillDisappear:animated];
    }
    
    @end
    

    现在我的代码正在处理iOS 6.1.3,5.5.1和4.3.5版本,具有完全相同的行为 .

  • 0

    我自己解决了 . 当我将Movie Player作为子视图添加到容器视图时,我不需要使用用 MPMoviePlayerViewController 创建的实际视图控制器,它旨在用于以模态方式或在其他vc层次结构中呈现它 .

    对于具有可以作为子视图添加到其他视图的电影播放器视图的单一目的, MPMoviePlayerController 的视图属性就足够了 .

    直到iOS 6都有效,但iOS 6在资源管理/生命周期方面似乎有所不同 .

    示例项目使用工作代码进行更新 .

  • 1

    我有同样的问题,但从网址加载视频(在网络上)

    以前我:

    • 已订阅 MPMoviePlayerPlaybackDidFinishNotification 通知

    • 初始化 MPMoviePlayerViewController (此阶段没有内容网址)

    • 通过 presentMoviePlayerViewControllerAnimated 提交:

    • 当它出现在屏幕上时,我加载了流式网址(异步)

    • 当网址回来时,我会在 MPMoviePlayerViewController 'moviePlayer上设置内容网址

    正如你所说的那样,偶尔_2582070会卡住并且在用户点击退出时不会自行解除,为了解决这个问题,我改变了自动播放顺序,因此流程变为:

    • 已订阅 MPMoviePlayerPlaybackDidFinishNotification 通知

    • 初始化 MPMoviePlayerViewController (此阶段没有内容网址)

    • Set the moviePlayer's shouldAutoplay boolean to NO

    • 通过 presentMoviePlayerViewControllerAnimated 提交:

    • 当它出现在屏幕上时,我加载了流式网址(异步)

    • 当网址回来时,我会在 MPMoviePlayerViewController 'moviePlayer上设置内容网址

    • Set the moviePlayer's shouldAutoplay boolean to YES

    由于这两个变化,我还没有看到控制器卡住了

  • 1

    我在iOS 6上有类似的东西 .

    你试图在全屏后强迫玩家玩吗?例如,再次调用 [MPMoviePlayerController play] - 这部分解决了我遇到的问题 .

  • 1

    设置播放器的内容网址后,请检查确切的网址 . 它可能包含一些非法字符 .

    NSLog(@"%@", player.contentURL);
    

    模拟器删除空格但设备没有 . 这就是发生在我身上的事 .

  • 2

    解决方案是创建一个属性来保留MPMoviePlayerController类

    @property (nonatomic, retain) MPMoviePlayerController *moviePlayerController;
    

    并使用控制器中的属性

    self.moviePlayerController = [[MPMoviePlayerController alloc] init];
    
    [_viewMediaPlayer addSubview:self.moviePlayerController.view];
    

    iOS6中有一个错误,当以全屏模式进入时,MPMoviePlayerController被取消分配http://openradar.appspot.com/12327997

  • 0

    所以对我来说这个解决方案有效

    if( !( player.playbackState == MPMoviePlaybackStatePlaying ) ) {
        player.shouldAutoplay = YES;
        [player prepareToPlay];
        [player stop];
        [player play];
    }
    

    添加“shouldAutoplay”和“stop”

    问候,伊丽莎

  • 1

    生成URL后,只需将shouldAutoplay布尔值添加到YES即可 .

    像这样:

    NSString *path = [[NSBundle mainBundle] pathForResource:videoFileName ofType:@"mp4" inDirectory:nil];
        NSURL *movieURL = [NSURL fileURLWithPath:path];
        MPMoviePlayerController *player = [[MPMoviePlayerController alloc] init]; 
    
        player.contentURL = movieURL;
        player.controlStyle = MPMovieControlStyleNone;    
    
        player.shouldAutoplay = YES;
        [player prepareToPlay];
        player.fullscreen = YES;
    
        [player.view setFrame:[[[[UIApplication sharedApplication] delegate] window] frame]];  // player's frame must match parent's
    
        [[[[UIApplication sharedApplication] delegate] window] addSubview: player.view];
    
        [player play];
    
  • 3

    解决这个问题的另一种方法是使用完整的屏幕通知回调:

    1)为电影播放器MPMoviePlayerDidEnterFullscreenNotification添加通知 . 2)在播放电影之前,设置一个布尔值,表示电影正在进入全屏 . 3)在全屏幕回调以及电影完成回叫中将布尔值清除为NO . 4)在你的viewWillDisappear中,检查你的布尔值,看看你的电影是否进入全屏,并根据需要进行处理 .

    此外,在呈现MPMoviePlayerViewController时,在呈现后使用setFullScreen函数可能会导致影片在iOS6上停止 .

  • 8

    My WORKING solution:

    我有同样的问题,当我尝试播放视频时,它会在一秒钟之后立即停止:

    [MPCloudAssetDownloadController] Prioritization requested for media item ID: 0
    [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 0, on player: 1)
    

    solved 它在 play 命令之前放了 stop 命令:

    [playerController stop];
    [playerController play];
    

    现在它完美无缺!

相关问题