후 현재 AVPlayer를 실행 항목으로 중단 할 그 때문에, 될 수 있습니다.
또한 AVPlayer에 항목을로드하기 전에 코드 (코드 아래)를 구현했는지 확인하십시오. 백그라운드에서 오디오를 재생할 수있는 기능을 제공합니다.
인터럽트 처리기를 구현하고 추가하면 다른 오디오/인터럽트가 중지 된 후에 중지 된 오디오를 다시 재생할 수 있습니다. 그 아래 청취자가 전화 할 것입니다.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleAudioSessionInterruption:)
name:AVAudioSessionInterruptionNotification
object:aSession];
및 관리 AVPlayer를 플레이/그것을 다시 일시 :
- (void)handleAudioSessionInterruption:(NSNotification*)notification {
NSNumber *interruptionType = [[notification userInfo] objectForKey:AVAudioSessionInterruptionTypeKey];
NSNumber *interruptionOption = [[notification userInfo] objectForKey:AVAudioSessionInterruptionOptionKey];
switch (interruptionType.unsignedIntegerValue) {
case AVAudioSessionInterruptionTypeBegan:{
// • Audio has stopped, already inactive
// • Change state of UI, etc., to reflect non-playing state
IsInteruptionOccured=YES;
} break;
case AVAudioSessionInterruptionTypeEnded:{
// • Make session active
// • Update user interface
// • AVAudioSessionInterruptionOptionShouldResume option
IsInteruptionOccured=NO;
[[AVAudioSession sharedInstance] setActive: YES error: nil];
if (interruptionOption.unsignedIntegerValue == AVAudioSessionInterruptionOptionShouldResume) {
// Here you should continue playback.
// Resume after exteranl interruption.
[_audioPlayer play];
BOOL isPlayingWithOthers = [[AVAudioSession sharedInstance] isOtherAudioPlaying];
// test it with...
NSLog(@"other audio is playing %d",isPlayingWithOthers);
}
} break;
default:
break;
}
}
는 이미 AppDelegate에 이러한 코드를 추가하고 배경 모드도에있다. – Giresh
내 측면에서 완벽하게 작동합니다. 하지만 저는 YMCAudioPlayer를 사용하여 음악을 연주했습니다. –
다음 단계에 따라 테스트 해주세요. 1. 앱 재생 미디어를 엽니 다. 2. 플레이어를 중지합니다. 3. 사과 음악 앱을 열고 음악을 연주 한 다음 음악을 중지하십시오. 4. 이제 앱이 백그라운드 모드에 있습니다. 백그라운드 모드에서 앱 미디어 플레이어를 재생 해 봅니다. 결과보기 – Giresh