0

我正在尝试从视图控制器播放电影。我正在使用下面的代码来做到这一点:

VideoPlayerViewController* moviePlayer = [self.storyboard instantiateViewControllerWithIdentifier:@"videoPlayerController"];
moviePlayer.view.frame = rect;
UIWindow *window = [[[UIApplication sharedApplication] windows] lastObject];
[window.rootViewController presentViewController:moviePlayer animated:NO completion:nil];
[moviePlayer playMoviesForItems:items];

通常它工作正常。但有时,电影开始了,但我看不到视频,我只能听到声音。

在一切之上播放视频的最佳方式是什么?

4

2 回答 2

1
NSString *path = [[NSBundle mainBundle] pathForResource:@"myVideo" ofType:@"mp4"];   

MPMoviePlayerController *myPlayer = [[MPMoviePlayerController alloc] init];
myPlayer.shouldAutoplay = YES;
myPlayer.repeatMode = MPMovieRepeatModeOne;
myPlayer.fullscreen = YES;
myPlayer.movieSourceType = MPMovieSourceTypeFile;
myPlayer.scalingMode = MPMovieScalingModeAspectFit;
myPlayer.contentURL =[NSURL fileURLWithPath:path];
[self.view addSubview:myPlayer.view];
[myPlayer play];

另一种解决方案是转到另一个 ViewController 并在电影结束时将其关闭。

于 2013-05-21T13:06:22.073 回答
0

您也可以尝试使用 AVPlayer。在这种情况下,您可以在当前视图本身中播放视频,而无需为视频单独叠加。

这是播放多个 AVPlayer 的示例。您可以修改代码以播放单个视频。

于 2013-05-21T13:21:59.647 回答