这部电影播放得很好,但在播放之前就有一个快速的黑色闪光灯.这是将控制风格设置为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];
Run Code Online (Sandbox Code Playgroud)
Mar*_*rty 19
我刚刚遇到这个问题并通过向默认的NSNotificationCenter添加一个观察者来修复它,以找出电影何时完全准备好播放,然后将视图作为子视图添加到我的主视图中.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkMovieStatus:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
Run Code Online (Sandbox Code Playgroud)
...
if(moviePlayer.loadState & (MPMovieLoadStatePlayable | MPMovieLoadStatePlaythroughOK))
{
[pageShown.view addSubview:moviePlayer.view];
[moviePlayer play];
}
Run Code Online (Sandbox Code Playgroud)
在IOS 6中,mpmoviewplayer添加了一个新属性:readyForDisplay
这就是我正在玩的东西,到目前为止一直很好:
等待displayState改变,一旦准备就显示视频控制器:
- (void)moviePlayerPlayState:(NSNotification *)noti {
if (noti.object == self.movieController) {
MPMoviePlaybackState reason = self.movieController.playbackState;
if (reason==MPMoviePlaybackStatePlaying) {
[[NSNotificationCenter defaultCenter] removeObserver:self name: MPMoviePlayerPlaybackStateDidChangeNotification object:nil];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
while (self.movieController.view.hidden)
{
NSLog(@"not ready");
if (self.movieController.readyForDisplay) {
dispatch_async(dispatch_get_main_queue(), ^(void) {
NSLog(@"show");
self.movieController.view.hidden=NO;
});
}
usleep(50);
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
}
当播放状态更改为MPMoviePlaybackStatePlaying时,我们开始检查readyDisplayState是否要更改.
显然,在电影rect中有一段黑色闪光,直到足够的电影加载,因此它可以开始播放.这是我的解决方法:
创建一个UIImageView并将MPMoviePlayerController放入其中.这样你就可以将alpha设置为0.
一旦你打[玩家玩]; 要播放视频,请设置.5秒计时器.
完成时间后,将alpha更改为1.
这将使玩家隐形1/2秒(隐藏黑色闪光).
| 归档时间: |
|
| 查看次数: |
7614 次 |
| 最近记录: |