No audio on iOS app using the RemoteIO AudioUnit when the iPad is restarted
-
01-07-2021 - |
문제
I have a strange issue where an iOS app that I have developed works fine when I build and run it from XCode on the device. However, on restarting the device and running the app, I get no audio at all. If I subsequently kill the app and restart it from the device, I start getting audio again. I initially thought it was an Interruption Handler issue, but am not sure any more. Any help would be appreciated!
Here's my interruption handler just in case.
static void MyInterruptionListener (void *inUserData,
UInt32 inInterruptionState) {
printf ("Interrupted! inInterruptionState=%ld\n", inInterruptionState);
pediViewController *pediController = (__bridge pediViewController*)inUserData;
switch (inInterruptionState) {
case kAudioSessionBeginInterruption:
CheckError (AudioOutputUnitStop (pediController.effectState.rioUnit),
"Couldn't start RIO unit");
case kAudioSessionEndInterruption:
// TODO: doesn't work!
CheckError(AudioSessionSetActive(true),
"Couldn't set audio session active");
CheckError (AudioOutputUnitStart (pediController.effectState.rioUnit),
"Couldn't start RIO unit");
break;
default:
break;
};
}
해결책 2
The issue went away on upgrading to iOS 6. I did some intensive debugging by commenting out each and every line of code in the audio callback and testing by restarting the iPad and running the app again 3 times each. Finally it was solved by updating to iOS 6 on the device and running on that. I also got a huge performance boost in doing so!
다른 팁
You should handle the app going in and out of the background using the audio route change callback, not the interruption handler.
This is what worked for me anyway when I had a similar problem to your own (If I understand your problem correctly).
Here is an example
AudioSessionAddPropertyListener (
kAudioSessionProperty_AudioRouteChange,
audioRouteChangeListenerCallback,
(__bridge void*) self
);
void audioRouteChangeListenerCallback (
void *inUserData,
AudioSessionPropertyID inPropertyID,
UInt32 inPropertyValueSize,
const void *inPropertyValue
) {
// Ensure that this callback was invoked because of an audio route change
if (inPropertyID != kAudioSessionProperty_AudioRouteChange) return;
AudioEngine *audioObject = (__bridge AudioEngine *) inUserData;
// if application sound is not playing, there's nothing to do, so return.
if (NO == audioObject.isPlaying) {
NSLog (@"Audio route change while application audio is stopped.");
return;
} else {
CFDictionaryRef routeChangeDictionary = inPropertyValue;
CFNumberRef routeChangeReasonRef =
CFDictionaryGetValue (
routeChangeDictionary,
CFSTR (kAudioSession_AudioRouteChangeKey_Reason)
);
SInt32 routeChangeReason;
CFNumberGetValue (
routeChangeReasonRef,
kCFNumberSInt32Type,
&routeChangeReason
);
if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable) {
NSLog (@"Audio output device was removed; stopping audio playback.");
NSString *MixerHostAudioObjectPlaybackStateDidChangeNotification = @"MixerHostAudioObjectPlaybackStateDidChangeNotification";
[[NSNotificationCenter defaultCenter] postNotificationName: MixerHostAudioObjectPlaybackStateDidChangeNotification object: audioObject];
} else {
NSLog (@"A route change occurred that does not require stopping application audio.");
}
}
}