iOS SDK должен быть выше 4.0;
сначала в кодах ваших делегатов:
- (void)applicationDidEnterBackground:(UIApplication *)application {
if (isAbove4_0)
{
CTCallCenter *_center = [[CTCallCenter alloc] init];
_center.callEventHandler = ^(CTCall *call)
{
//NSLog(@"call:%@", call.callState);
if ([call.callState isEqualToString:CTCallStateIncoming])
{
[RadioPlayer pausePlayer];
}
};
}
}
затем,
Я использовал MPMoviePlayerController, и AVPlayer в порядке;
if (isAbove4_0) {
if (_mpmovieplayer == nil) {
_mpmovieplayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[_mpmovieplayer setMovieControlMode:MPMovieControlModeHidden];
}
[_mpmovieplayer setContentURL:url];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
// This is necessary if you want to play a sequence of songs, otherwise your app will be
// killed after the first one finishes.
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
UIBackgroundTaskIdentifier newTaskId = UIBackgroundTaskInvalid;
[_mpmovieplayer play];
newTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];
if (newTaskId != UIBackgroundTaskInvalid && bgTaskId != UIBackgroundTaskInvalid)
[[UIApplication sharedApplication] endBackgroundTask: bgTaskId];
bgTaskId = newTaskId;
}
PS: мой английский плохой, я надеюсь, что это может быть полезно для вас:)