0
我有一個課程可以播放帶有AVAudioPlayer
的重複背景音樂循環,並且在特定場合使用MPMoviePlayerController
播放帶有自己音軌的全屏視頻。爲了給只有一個軌道中的時候,我啓動視頻之前停止背景音樂:爲什麼MPMoviePlayerController會在電影結束後阻止音頻的恢復?
-(void)startVideo{
[backgroundMusic stop];
MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"videofile" ofType:@"m4v"]]];
[self presentMoviePlayerViewControllerAnimated:mp];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoOver) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[mp.moviePlayer play];
[mp release];
}
-(void)videoOver{
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
if(![backgroundMusic play]){
NSLog(@"bad: can't resume bg music!");
[backgroundMusic release];
backgroundMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"videofile" ofType:@"m4v"]] error:NULL];
backgroundMusic.delegate = self;
backgroundMusic.numberOfLoops = -1;
[backgroundMusic play];
}
}
的恢復而無須重新創建AVAudioPlayer
對象工作正常上類似的代碼上(即play
方法返回YES) os版本高達幷包括3.2。但在iOS4上,play
方法始終返回NO,並且必須重新創建該對象。爲什麼是這樣,我可以正確地恢復背景音軌(我有上面使用的解決方案是不可接受的情況)?