MPMoviePlayerViewController 不为 IOS 8.4 播放视频

Posted

技术标签:

【中文标题】MPMoviePlayerViewController 不为 IOS 8.4 播放视频【英文标题】:MPMoviePlayerViewController not playing videos for IOS 8.4 【发布时间】:2015-07-09 08:07:52 【问题描述】:

我的视频在 ios 8.3 及更早版本上播放良好。但在最近更新 IOS 8.4 视频播放器后停止工作。视频没有被播放,它立即进入 MPMoviePlaybackComplete: 方法。

Here is my code :

     self.player = [[MPMoviePlayerViewController alloc] initWithContentURL:fileURL];

    [self.player.moviePlayer setFullscreen:YES animated:YES];

      if(subtitlesPathStr)
    [self.player.moviePlayer openSRTFileAtPath:subtitlesPathStr
                                       completion:^(BOOL finished) 

                                           // Activate subtitles

                                           [self.player.moviePlayer showSubtitles];
    [self.navigationController presentMoviePlayerViewControllerAnimated:self.player];

                                        failure:^(NSError *error) 

                                   NSLog(@"Error: %@", error.description);
           

             ];
        else [self.navigationController presentMoviePlayerViewControllerAnimated:self.player];

     [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(MPMoviePlayerLoadStateDidChange:)
                                                     name:MPMoviePlayerLoadStateDidChangeNotification
                                                   object:nil];

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

        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(MPMoviePlaybackComplete:)    
                                                     name:MPMoviePlayerPlaybackDidFinishNotification
                                                   object:nil];

谁能告诉我如何解决这个问题?

【问题讨论】:

我们的应用中存在同样的问题 【参考方案1】:

根据播放时间和可播放时长添加重置视频方法。

   - (void)playbackDidFinish:(NSNotification*)aNotification 
        MPMoviePlayerController *moviePlayer = aNotification.object;
        NSNumber *reason = [aNotification.userInfo objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];
        if ([reason intValue] == MPMovieFinishReasonPlaybackEnded) 
            if (moviePlayer.currentPlaybackTime == moviePlayer.playableDuration) 
                [moviePlayer stop];
            
        
    

【讨论】:

我遇到了同样的问题,在我的情况下,视频第一次播放良好,但是当我创建新视频并尝试重新加载新视频时,应用程序崩溃。代码在 8.4 之前的版本中运行良好,在 8.4 中无法运行。请告诉我如何重置视频

以上是关于MPMoviePlayerViewController 不为 IOS 8.4 播放视频的主要内容,如果未能解决你的问题,请参考以下文章