如何使用属性Bool应该自动播放MPMovieplayercontroller ios

时间:2014-07-14 08:49:28

标签: ios objective-c mpmovieplayercontroller

我想在没有点击播放按钮的情况下自动播放视频。 所以我找到了MPMovieplayerController“BOOl Shouldautoplay”的属性 但不知道如何使用它。

2 个答案:

答案 0 :(得分:0)

moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:fileName]];

    moviePlayer.initialPlaybackTime = 0;
    moviePlayer.view.frame = self.view.frame ;

    [self.view addSubview:moviePlayer.view] ;

    moviePlayer.shouldAutoplay = YES;
    [moviePlayer prepareToPlay];

希望有所帮助

答案 1 :(得分:0)

这是另一种方式

-(void) mpVideo:(NSString *)fileName {

    videoFileName=fileName;
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:fileName]];

    moviePlayer.initialPlaybackTime = 0;
    moviePlayer.view.frame = self.view.frame ;
    [orientationHandler VideoStart];
    [self.view addSubview:moviePlayer.view] ;
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlaybackDidFinish:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:moviePlayer];
    moviePlayer.shouldAutoplay = NO;
    [moviePlayer prepareToPlay];
}

-(void)moviePlaybackDidFinish:(NSNotification *)notification {

    // your custom code which you want to play after the player did finish playing
}