MPMoviePlayerViewController not playing videos for IOS 8.4

折月煮酒 提交于 2019-12-24 17:53:00

问题


My videos are playing well for IOS 8.3 and earlier versions. But after a recent update of IOS 8.4 Video Player stopped working. Videos are not getting played and immediately it's going to MPMoviePlaybackComplete: method.

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];

Can somebody tell me how to solve this issue ?


回答1:


Add your reset video method based on playbacktime and playableduration.

   - (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];
            }
        }
    }


来源:https://stackoverflow.com/questions/31311636/mpmovieplayerviewcontroller-not-playing-videos-for-ios-8-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!