重新启动iPad时,使用RemoteIO AudioUnit的iOS应用程序上没有音频

时间:2012-09-10 16:36:47

标签: ios core-audio audiounit remoteio

我有一个奇怪的问题,我开发的iOS应用程序在我从设备上的XCode构建和运行时工作正常。但是,在重新启动设备和运行应用程序时,我根本没有音频。如果我随后杀死应用程序并从设备重新启动它,我会再次开始获取音频。我最初认为这是一个Interruption Handler问题,但我不确定了。任何帮助将不胜感激!

以下是我的中断处理程序以防万一。

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 个答案:

答案 0 :(得分:1)

您应该使用音频路由更改回调处理应用程序进出后台,而不是中断处理程序。

当我遇到类似的问题(如果我理解你的问题)时,这对我有用。

这是一个例子

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.");
        }
    }
}

答案 1 :(得分:0)

升级到iOS 6后问题就消失了。我通过在音频回调中评论每一行代码并通过重新启动iPad并再次运行应用程序3次来进行一些密集调试。最后,它通过在设备上更新到iOS 6并在其上运行来解决。这样做我也获得了巨大的性能提升!