MPMoviePlayerViewController – 如何消除video加载时的黑色闪光?
我正在使用MPMoviePlayerViewController在我的应用程序中显示video。 有用! 唯一的问题是在电影播放之前有一个黑色闪光灯。
我怎样才能摆脱黑色闪光? 我已经看到了其他线程,但他们似乎没有解释,与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];
经过不断的迭代和调整,我偶然发现了一个使用MPMoviePlayerController的解决scheme。
不要忘记在.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; } }