电影播放正常,但是在播放之前会出现快速的黑色闪光。将controlstyle设置为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];

最佳答案

我只是遇到了这个问题,并通过将观察者添加到默认的NSNotificationCenter来确定电影何时完全可以播放,然后将 View 作为 subview 添加到主 View 中,从而解决了该问题。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkMovieStatus:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];

...
if(moviePlayer.loadState & (MPMovieLoadStatePlayable | MPMovieLoadStatePlaythroughOK))
{
    [pageShown.view addSubview:moviePlayer.view];
    [moviePlayer play];
}

关于ios4 - MPMoviePlayerController在视频开始时导致黑色闪烁,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4216021/

10-09 09:14