Ios 如果在后台模式下播放时手机响起
我正在制作一个iphone应用程序(直播广播应用程序) 我的应用程序支持后台模式 但是,如果在后台模式下播放广播应用程序时手机响了,我的应用程序将因错误而停止Ios 如果在后台模式下播放时手机响起,ios,ios5,background,mpmovieplayercontroller,multitasking,Ios,Ios5,Background,Mpmovieplayercontroller,Multitasking,我正在制作一个iphone应用程序(直播广播应用程序) 我的应用程序支持后台模式 但是,如果在后台模式下播放广播应用程序时手机响了,我的应用程序将因错误而停止 MP AVAudioSessionDelegateMediaPlayerOnly end interruption. Interruptor <Phone> category <completed> resumable <0>, _state = 6 MP endInterruptionFromInt
MP AVAudioSessionDelegateMediaPlayerOnly end interruption. Interruptor <Phone> category <completed> resumable <0>, _state = 6
MP endInterruptionFromInterruptor :: resuming playback
viewController.m
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil];
moviePlayer = [[MPMoviePlayerController alloc] init];
[moviePlayer setContentURL:... m3u8];
[moviePlayer play];
您需要添加以下内容:[[UIApplication sharedApplication]开始接收RemoteControlEvents]
- (void)applicationDidEnterBackground:(UIApplication *)application
{
bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
// Clean up any unfinished task business by marking where you.
// stopped or ending the task outright.
[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
// Start the long-running task and return immediately.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Do the work associated with the task, preferably in chunks.
[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
});
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
}
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil];
moviePlayer = [[MPMoviePlayerController alloc] init];
[moviePlayer setContentURL:... m3u8];
[moviePlayer play];