MPMoviePlayerController播放视频,但在iOS 8中显示黑屏

时间:2015-09-03 14:02:49

标签: ios iphone ios8 mpmovieplayercontroller mpmovieplayer

我正在使用MPMoviePlayerController播放存储在主捆绑中的视频。 但是某个时候当我播放视频时播放视频但显示黑屏,在这种情况下,搜索栏也能正常工作。 那时如果我切换到全屏模式并返回正常模式(或者以后台模式发送应用程序并将其置于前台模式),那么它会正常播放(恢复)视频(没有显示黑屏)。

请参阅以下应用的屏幕截图:enter image description here

更新

以下是用于播放视频的代码:

- (void)playVideo:(NSString *)filepath {

    NSLog(@"get audiosession");
    AVAudioSession *audiosession =     [AVAudioSession sharedInstance];
    [audiosession setCategory:AVAudioSessionCategoryAmbient error:nil ];
    NSLog(@"finish audiosession");
    appDelegate.currentCourseNoExt = [filepath stringByDeletingPathExtension];

    NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@.mp3",appDelegate.currentCourseNoExt]];
    NSError *error;
    NSLog(@"get avaudioplayer");
    AVAudioPlayer *avPlayerTemp = [[AVAudioPlayer alloc]
                                   initWithContentsOfURL:url
                                   error:&error];
    NSLog(@"finish avaudioplayer");

    avPlayer = avPlayerTemp;
    NSLog(@"copy avaudioplayer");

    // get frame
    CGRect frame = self.view.frame;
    frame.origin.x = 0;
    frame.origin.y = 0;
    frame.size.height -= 0;
    NSLog(@"self.view.frame - %@",NSStringFromCGRect(self.view.frame));

    appDelegate.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:filepath]];
    appDelegate.moviePlayer.view.frame = frame;
    appDelegate.moviePlayer.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

    [self.view addSubview:appDelegate.moviePlayer.view];
    [self.view sendSubviewToBack:(appDelegate.moviePlayer.view)];

    imgBottomAdvertisement.frame = CGRectMake(0, appDelegate.moviePlayer.view.frame.size.height - imgBottomAdvertisement.frame.size.height, imgBottomAdvertisement.frame.size.width, imgBottomAdvertisement.frame.size.height);
    [appDelegate.moviePlayer.backgroundView addSubview:imgBottomAdvertisement];

    appDelegate.moviePlayer.currentPlaybackRate= 1.0;
    appDelegate.moviePlayer.currentPlaybackTime =  appDelegate.SMile.doubleValue;

    [avPlayer setRate:0];

    [appDelegate.moviePlayer play ];
    [avPlayer play];
}

从ViewController的viewDidAppear方法调用上述方法。

0 个答案:

没有答案