何時間も前から 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 から抽出されたものです。そして、サンプルが正常に動作するのは奇妙です!
何が悪いのか理解できますか?
ありがとう。