MPMoviePlayerViewController关闭不播放

时间:2015-06-23 14:24:13

标签: ios video mpmovieplayercontroller mpmovieplayer

问题视频可以在以下位置看到: http://app.bowerchat.com/images/118_1435046739658.mp4

MPMoviePlayerViewController在没有播放的情况下立即解散。 可能是什么原因?有些视频可以很好地加载并播放。

如何检查视频是否可以播放? 我试过了

NSLog(@"%lu",(unsigned long)self.mpController.moviePlayer.loadState);
        NSLog(@"%d",self.mpController.moviePlayer == nil);

结果始终为0 - 0

播放视频的MY代码

 self.mpController = [[MPMoviePlayerViewController alloc] initWithContentURL:moveUrl];
        [self.mpController.moviePlayer prepareToPlay];
        NSLog(@"%lu",(unsigned long)self.mpController.moviePlayer.loadState);
        NSLog(@"%d",self.mpController.moviePlayer == nil);

        [parent presentMoviePlayerViewControllerAnimated:self.mpController];

2 个答案:

答案 0 :(得分:0)

原因可能是具有扩展* .mp4的电影实际上是不同类型的。

还尝试添加以下内容:

self.mpController.moviePlayer.shouldAutoplay = YES;
[self.mpController.moviePlayer play];

答案 1 :(得分:0)

试试这个代码段:

-(void)setupMovie
{
    NSURL *movieURL = [NSURL fileURLWithPath:movieURL];

    self.mpController =  [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    self. mpController.scalingMode = MPMovieScalingModeAspectFill;
    self. mpController.controlStyle = MPMovieControlStyleNone;
    self.mpController.view.frame = self.view.frame;

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

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

    [self.view addSubview:self.mpController.view];
    [self.mpController prepareToPlay];
}


- (void)moviePlayBackDidFinish:(MPMoviePlayerController *)player
{
    [self.mpController.view removeFromSuperview];
}

- (void)moviePlayerPlaybackStateDidChange:(NSNotification*)notification
{
    if (self. mpController.isPreparedToPlay) {
        [self. mpController play];
    }
}

并确保movieURL正确,并且此提供的网址存在视频

相关问题