问题描述
我正在使用 MPMoviePlayerViewController 在我的应用中显示视频.有用!唯一的问题是电影播放前有一个黑色闪光.
I'm using MPMoviePlayerViewController to show a video in my app. It works! Only problem is that there's a black flash just before the movie plays.
我怎样才能摆脱黑色闪光?我看过其他线程,但它们似乎没有适用于 MPMoviePlayerViewController 的解释,并且对于像我这样的新手来说足够具体/详细(大多数是针对 MPMoviePlayerController).
How can I get rid of the black flash? I've seen other threads, but they don't seem to have an explanation that works with MPMoviePlayerViewController and is sufficiently specific/detailed for a novice like me (most are for 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];
推荐答案
经过无休止的迭代和调整,我偶然发现了使用 MPMoviePlayerController 的解决方案.
After endlessly iterating and tweaking, I stumbled my way into a solution using MPMoviePlayerController.
不要忘记在 .h 文件中声明属性,例如
Don't forget to declare the property in the .h file, e.g.
@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;
}
}
这篇关于MPMoviePlayerViewController -- 如何消除视频加载时的黑闪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!