MPMoviePlayerController multitasking problem
I develop an application on iphone that uses MPMoviePlayerController to play aud开发者_如何学运维io file. When Application goes to background, if mpmovieplayer is playing, iphone continues to play the current music, but when it ends, the next track doesn't start.
I try to start the next audio file in the MPMoviePlayerPlaybackDidFinishNotification and when I follow the code using the debugger I can see that the method is invoked and the code executed, bat the next audio file still doesn't start.
Is this possible on iOS 4.1 or this is a limitation?
Best regards Samantha
You should read the Technical Q&A QA1668: How to play audio in the background with MPMoviePlayerController.
Summary of the steps needed:
- declare that your application supports background execution for audio
- assign an appropriate category to your audio session (default category is not ok)
I got it working by putting following two lines in Delegate file:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
may be you forget to add this in
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
}
精彩评论