如何在视频暂停的情况下初始化MPMoviePlayerController

时间:2014-11-13 20:33:33

标签: ios mpmovieplayercontroller

我正在为iOS开发一个应用程序,它显示一个电影,我的方法是一个类方法,这是代码

Functions.m

static   MPMoviePlayerController *moviePlayer = nil;
+(void)playMP4Movie:(NSString *)moviename
       insideOfView:(UIView *)view
           autoplay:(BOOL)autoplay{

    NSString *path          = [[NSBundle mainBundle] pathForResource:moviename ofType:@"mp4"];
    NSURL *videoURL         = [NSURL fileURLWithPath:path];
    moviePlayer             = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
    moviePlayer.repeatMode  = MPMovieRepeatModeOne; // for looping
    moviePlayer.view.frame  = view.bounds;

    [moviePlayer prepareToPlay];

    if (autoplay)   { [moviePlayer play]; }
    else            { [moviePlayer stop];  }

    [view addSubview:moviePlayer.view];
}

我希望通过视频暂停来调用它:

[Functions playMP4Movie:videoName insideOfView:_videoPlayerView autoplay:NO];

它显示了我的视频,但无论我将自动播放设置为YES还是NO,结果总是相同的...任何帮助我都会感激

1 个答案:

答案 0 :(得分:2)

尝试使用:

if (autoplay)   { [moviePlayer setShouldAutoplay:YES]; }
else            { [moviePlayer setShouldAutoplay:NO]; }

看看你是否有更好的运气。