0
我有一個應用程序,在觸摸視圖後再播放電影,然後完成電影。我在視圖上放置了一個按鈕。點擊按鈕後會播放第二部電影。但它似乎只是然後加載和一個短的黑屏出現。我想避免現在黑屏......連續播放兩個視頻導致短黑屏
繼承人的代碼:
初始化在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];
}
但這裏會出現一個短暫的黑屏,可能同時劇場2被加載,然後播放。
如何避免黑屏?
格爾茨
我會嘗試一個,但有一條評論會讓我失望......「從iOS 5開始,看起來AVQueuePlayer不再預緩衝,它預先緩衝了iOS 4中的下一首曲目。」 – spankmaster79 2012-03-08 12:45:27
@ spankmaster79它是如何爲你工作的? – Till 2012-03-15 19:09:48
它確實爲我工作。在完成的視頻中放置按鈕時出現問題,但似乎是另一個問題 – spankmaster79 2012-03-19 09:27:43