我正在使用MPMoviePlayerViewController在我的应用中显示视频。有用!唯一的问题是电影播放前有黑色闪光。
如何摆脱黑色闪光?我见过其他线程,但它们似乎没有与MPMoviePlayerViewController一起使用的解释,并且对于像我这样的新手来说是足够具体/详细的(大部分用于MPMoviePlayerController)。
非常感谢任何帮助!
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"aiw_intro_video" ofType:@"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerViewController *mpvc = [[MPMoviePlayerViewController alloc] init];
mpvc.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
mpvc.moviePlayer.controlStyle = MPMovieControlStyleNone;
[mpvc.moviePlayer setContentURL:fileURL];
[mpvc.moviePlayer play];
[self presentViewController:mpvc animated:NO completion:NULL];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:mpvc.moviePlayer];
答案 0 :(得分:2)
经过无休止的迭代和调整后,我偶然发现了使用MPMoviePlayerController的解决方案。
不要忘记在.h文件中声明属性,例如
@property (strong, nonatomic) MPMoviePlayerController *moviePlayer;
然后
// Add default image to smooth transition
UIImage *myImage = [UIImage imageNamed:@"aiw_launch1136_black.png"];
self.videoStartFrame.image = myImage;
// Play the intro video
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"aiw_intro_video" ofType:@"mp4"]]];
self.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
self.moviePlayer.controlStyle = MPMovieControlStyleNone;
[self.moviePlayer prepareToPlay];
[self.moviePlayer play];
[self.moviePlayer.view setFrame:self.view.bounds];
[self.view addSubview:self.moviePlayer.view];
self.moviePlayer.view.hidden = YES;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(isMovieReady:) name:MPMoviePlayerLoadStateDidChangeNotification object:self.moviePlayer];
// Detect that the video is ready and unhide the view
-(void)isMovieReady:(NSNotification *)notification {
MPMoviePlayerController *moviePlayer = [notification object];
if(moviePlayer.loadState & (MPMovieLoadStatePlayable | MPMovieLoadStatePlaythroughOK))
{
self.moviePlayer.view.hidden = NO;
}
}