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;
}
추신 : 내 영어는 내가이 당신 :)에게 도움이 될 수있는 희망 가난
를 다음을 추가 음악은 배경에 있습니다. iOS가 지원하는 백그라운드 프로세스 중 하나입니다. – Robin