【问题标题】:How to check that audio is routed to Bluetooth Handsfree during a call in iOS?如何在 iOS 通话期间检查音频是否路由到蓝牙免提?
【发布时间】:2012-11-15 23:38:04
【问题描述】:

当有来自 iOS 设备的任何传入/传出呼叫时,我想检测以下事件:

  1. 是否连接了任何蓝牙耳机设备。
  2. 音频是否路由到任何蓝牙耳机设备。

我是蓝牙配件编程的新手,有什么办法吗?

【问题讨论】:

    标签: ios bluetooth


    【解决方案1】:

    我解决了如下:

    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
        NSError *err;
    
        // close down our current session...
        [audioSession setActive:NO error:nil];
        AudioSessionAddPropertyListener(kAudioSessionProperty_AudioRouteChange,   &AudioSessionManager_audioRouteChangedListener, self);
    
    
        void AudioSessionManager_audioRouteChangedListener (void *inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void *inData)
        {
            NSLog(@"AudioSessionManager_audioRouteChangedListener");
            MyAppDelegate *instance = (MyAppDelegate *)inClientData;
            CFDictionaryRef routeChangeDictionary = inData;
    
    
            // extract the route change reason...
    
            CFNumberRef routeChangeReasonRef = CFDictionaryGetValue (routeChangeDictionary, CFSTR(kAudioSession_AudioRouteChangeKey_Reason));
            SInt32 routeChangeReason = kAudioSessionRouteChangeReason_Unknown;
            if (routeChangeReasonRef)
                CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);
    
            // extract the old route..
    
            CFStringRef newRoute;
            if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 5.0)
            {
                newRoute = CFDictionaryGetValue(routeChangeDictionary, @"OutputDeviceDidChange_NewRoute");
            }
            else
            {
                newRoute = CFDictionaryGetValue(routeChangeDictionary, @"OutputDeviceDidChange_NewRoute");
            }
    
    
            CFStringRef oldRoute;
            oldRoute = CFDictionaryGetValue(routeChangeDictionary, @"OutputDeviceDidChange_OldRoute");
            NSLog(@"newRouteString:%@ oldRoute:%@",newRoute,oldRoute);
    
            [instance onAudioRouteChangedWithReason:routeChangeReason newRoute:(NSString *)newRoute oldRoute:(NSString *)oldRoute];
        }
    

    【讨论】:

      【解决方案2】:

      在下面的代码中,检查“micConnected”的值以查看耳机是否连接。

      AudioSessionInitialize(NULL, NULL, NULL, NULL);    
      UInt32 propertySize, micConnected;
          AudioSessionGetProperty(kAudioSessionProperty_AudioInputAvailable, &propertySize, &micConnected);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-12-12
        • 2011-01-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-01-20
        相关资源
        最近更新 更多