У меня есть приложение, в котором я играю фильм после касания экрана, а затем, когда фильм заканчивается.Я помещаю кнопку в представление.При нажатии на кнопку воспроизводится второй фильм.Но похоже, что он только потом загружается и появляется короткий черный экран.Теперь я хочу избежать черного экрана ...
Вот код:
Инициализация в 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