我有一个应用程序,我可以在触摸视图后播放电影,然后当电影结束时。我在视图上放置了一个按钮。单击该按钮后,将播放第二部影片。但似乎只有在加载之后,才会出现一个短小的黑屏。我现在想避开黑屏...
代码如下:
viewDidLoad中的初始化
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString *movpath = [[NSBundle mainBundle]
pathForResource:@"movie1"
ofType:@"m4v"];
mpviewController =
[[MPMoviePlayerViewController alloc]
initWithContentURL:[NSURL fileURLWithPath:movpath]];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
mp = [mpviewController moviePlayer];
// [mp setMovieControlMode:MPMovieControlModeHidden];
// [mp.view setFrame:CGRectMake(0, 0, 250, 263)];
mp.controlStyle = MPMovieControlStyleNone;
mp.shouldAutoplay = NO;
[mp prepareToPlay];
[mp pause];然后在故事板上,我调用了startAnimation
- (IBAction)startAnimation:(id)sender {
NSLog(@"Animation 1");
[self.view addSubview:mpviewController.view];
[mp play];
}在这部电影结束后,我按下按钮
- (void) movieFinishedCallback:(NSNotification*) aNotification {
NSLog(@"...movie done");
// generate start button for animation 2
startAnimation2Button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
startAnimation2Button.tag = 1;
[startAnimation2Button addTarget:self action:@selector(startAnimation2:) forControlEvents:UIControlEventTouchUpInside];
startAnimation2Button.frame = CGRectMake(130, 230, 070, 070);
startAnimation2Button.userInteractionEnabled = YES;
startAnimation2Button.alpha = 0.1;
[self.view addSubview:startAnimation2Button];
}然后,在触摸按钮之后,第二个动画开始
- (IBAction)startAnimation2:(id)sender {
NSLog(@"Animation 2");
NSString *movpath = [[NSBundle mainBundle]
pathForResource:@"movie2"
ofType:@"m4v"];
[mp setContentURL:[NSURL fileURLWithPath:movpath]];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(movieFinishedCallback2:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[mp play];
}但这里出现了一个很短的黑屏,可能是在movie2加载并播放的时候。
如何避免黑屏?
Greetz
发布于 2012-03-08 18:39:46
在使用MPMoviePlayerController时,您无法完全摆脱视频之间的预缓冲延迟(黑相)。
请改用AVQueuePlayer。
AVQueuePlayer是AVPlayer的一个子类,您可以使用它按顺序播放多个项目。
有关这一问题,请参阅其他questions and issues。
https://stackoverflow.com/questions/9615994
复制相似问题