Я пытаюсь решить проблему AVAudioSession много часов назад и не добился успеха !!
Я нашел много парней, которые говорили о проблемах с endInterruption, но никто из них не говорил об этой ошибке:
Unable to reactivate the audio session after the interruption ended: Error Domain=NSOSStatusErrorDomain Code=560161140 "The operation couldn’t be completed. (OSStatus error 560161140.)"
Я попытался преобразовать этот код в ASCII, чтобы проверить результаты аудиокода, но с этим номером ничего не связано.
Мой код для инициации сеанса:
- (void) setupAudioSession {
mySession = [AVAudioSession sharedInstance];
[mySession setDelegate: self];
NSError *audioSessionError = nil;
[mySession setCategory: AVAudioSessionCategoryPlayback error: &audioSessionError];
if (audioSessionError != nil) {
NSLog (@"Error setting audio session category: %@", [audioSessionError description]);
return;
}
// Activate the audio session
[mySession setActive: YES error: &audioSessionError];
if (audioSessionError != nil) {
NSLog (@"Error activating audio session during initial setup: %@", [audioSessionError description]);
return;
}
// Prepare audio file to play
NSBundle *mainBundle = [NSBundle mainBundle];
NSURL *bgSoundURL = [NSURL fileURLWithPath:[mainBundle pathForResource:@"bg_sound" ofType:@"aif"]];
bgPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:bgSoundURL error:&audioSessionError];
if (!bgPlayer) {
NSLog(@"No bgPlayer: %@", [audioSessionError description]);
}
[bgPlayer setNumberOfLoops:-1];
[bgPlayer prepareToPlay];
}
И код метода endInterruption:
- (void) endInterruptionWithFlags: (NSUInteger) flags {
if (flags & AVAudioSessionInterruptionFlags_ShouldResume) {
NSError *endInterruptionError = nil;
[[AVAudioSession sharedInstance] setActive: YES error: &endInterruptionError];
if (endInterruptionError != nil) {
NSLog (@"Unable to reactivate the audio session after the interruption ended: %@", [endInterruptionError description]);
return;
} else {
NSLog (@"Audio session reactivated after interruption.");
if (interruptedWhilePlaying) {
self.interruptedWhilePlaying = NO;
// Resume playback by sending a notification to the controller object, which
// in turn invokes the playOrStop: toggle method.
NSString *MixerHostAudioObjectPlaybackStateDidChangeNotification = @"MixerHostAudioObjectPlaybackStateDidChangeNotification";
[[NSNotificationCenter defaultCenter] postNotificationName: MixerHostAudioObjectPlaybackStateDidChangeNotification object: self];
}
}
}
}
Большая часть этого кода была извлечена из примера Apple Mixer Host Sample.И странно, что образец отлично работает!
Ребята, вы можете понять, что не так?
Спасибо.