这是我的代码,应该播放嵌入在子视图中的视频,但它只显示没有控件的静止图像。
- (void)displayVideo:(NSURL *)videoURL
{
if (self.mediaPlayer) {
[self.mediaPlayer.view removeFromSuperview];
self.mediaPlayer = nil;
}
self.mediaPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
[self.mediaPlayer.moviePlayer prepareToPlay];
self.mediaPlayer.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
self.mediaPlayer.view.frame = CGRectMake(0, 0, self.mediaView.bounds.size.width, self.mediaView.bounds.size.height);
[self.mediaView addSubview:self.mediaPlayer.view];
[self.mediaPlayer.moviePlayer play];
}
我还尝试直接在 mediaPlayer 是 MPMoviePlayerController 而不是 MPMoviePlayerViewController 的地方加载媒体播放器,但只有黑色视图我得到的更少。
self.mediaPlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[self.mediaPlayer prepareToPlay];
self.mediaPlayer.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
self.mediaPlayer.view.frame = CGRectMake(0, 0, self.mediaView.bounds.size.width, self.mediaView.bounds.size.height);
[self.mediaView addSubview:self.mediaPlayer.view];
[self.mediaPlayer play];
谢谢你的帮助。