【问题标题】:No audio on iOS app using the RemoteIO AudioUnit when the iPad is restarted重新启动 iPad 时,使用 RemoteIO AudioUnit 的 iOS 应用程序没有音频
【发布时间】:2012-09-10 16:36:46
【问题描述】:

我有一个奇怪的问题,我开发的 iOS 应用程序在我从设备上的 XCode 构建和运行时运行良好。但是,在重新启动设备并运行应用程序时,我根本听不到音频。如果我随后终止该应用程序并从设备重新启动它,我将再次开始获取音频。我最初认为这是一个中断处理程序问题,但我不确定了。任何帮助将不胜感激!

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

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;
};

}

【问题讨论】:

    标签: ios core-audio audiounit remoteio


    【解决方案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.");
            }
        }
    }
    

    【讨论】:

    • 试过了,但没有解决问题。做了一些密集的调试,并认为这是一些 iOS 问题。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-03
      • 1970-01-01
      • 2012-05-09
      相关资源
      最近更新 更多