使用MPMoviePlayerController播放视频

时间:2015-07-27 18:07:52

标签: objective-c mpmovieplayercontroller ios8.3

当我打开视图时,我试图让视频单独启动,但只是它的声音有效。视图为空白。我正在使用MPMoviePlayerController执行此操作。

我的代码是:

@property (nonatomic, strong) MPMoviePlayerController *moviePlayer;

- (void)viewDidLoad {
    [super viewDidLoad];
    [self playVideo];
}

-(void)playVideo {
    NSString *videoFile = [[NSBundle mainBundle] pathForResource:@"fds" ofType:@"mp4"];
    self.moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:[NSURL fileURLWithPath:videoFile]];
    [self.playerView addSubview:self.moviePlayer.view];
    self.moviePlayer.fullscreen = YES;
    self.moviePlayer.allowsAirPlay = YES;
    [self.moviePlayer play];
}

1 个答案:

答案 0 :(得分:0)

尝试将playVideo调用移至viewWillAppear