MPMoviePlayerController 在视频开始时导致黑色闪烁 [英] MPMoviePlayerController causes flash of black at start of video
问题描述
电影播放正常,但在播放前有一个快速的黑色闪光.这是将 controlstyle 设置为 MPMovieControlStyleNone 导致的怪癖吗?
The movie plays just fine but there is a quick black flash right before it plays. Is this a quirk resulting from setting the controlstyle to MPMovieControlStyleNone?
NSString *url = [[NSBundle mainBundle] pathForResource:@"00" ofType:@"mov"];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc]
initWithContentURL:[NSURL fileURLWithPath:url]];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
//---play video in implicit size---
player.view.frame = CGRectMake(80, 64, 163, 246);
[self.view addSubview:player.view];
// Hide video controls
player.controlStyle = MPMovieControlStyleNone;
//---play movie---
[player play];
推荐答案
很明显,在加载足够多的电影以开始播放之前,电影 rect 中会出现黑色闪光.这是我的解决方法:
Evidently there is a flash of black in the movie rect until enough movie loads so it can start playback. Here is my workaround:
创建一个 UIImageView 并将 MPMoviePlayerController 放入其中.这样您就可以将 alpha 设置为 0.
Create a UIImageView and put the MPMoviePlayerController in it. That way you can set the alpha to 0.
只要你调用[player play];要播放视频,请设置 0.5 秒计时器.
As soon as you call [player play]; to play the video, set up a .5 second timer.
时间结束后,将 alpha 更改为 1.
When the time is done, change the alpha to 1.
这将使玩家隐形 1/2 秒(隐藏黑色闪光).
This will make the player invisible for 1/2 second (which hides the black flash).
这篇关于MPMoviePlayerController 在视频开始时导致黑色闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!