MPMoviePlayerController在视频开始时导致黑色闪烁 [英] MPMoviePlayerController causes flash of black at start of video
问题描述
电影播放效果不错,但播放前会有快速黑色闪光。这是将控制风格设置为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];
推荐答案
显然电影中有黑色闪光直到足够的电影加载,所以它可以开始播放。这是我的解决方法:
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.
一旦你打电话给[播放器];要播放视频,请设置.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屋!