检测连接音频设备的iOS [英] Detect attached audio devices iOS

查看:429
本文介绍了检测连接音频设备的iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出如何检测如果发现任何音频设备连接用iPhone / iPad / iPod的。我知道所有关于音频呼叫路由和路由变化回调,但这些并没有告诉我什么附加任何东西。它们只报告其中音频当前路由。我需要知道,举例来说,如果耳机和/或蓝牙音频时通过扬声器路由仍然连接。或者,例如,如果用户在使用蓝牙然后决定断开蓝牙耳机插头,我需要知道蓝牙断开即使音频仍然通过耳机进行路由选择。

I'm trying to figure out how to detect which if any audio devices are connected on iphone/ipad/ipod. I know all about the audio route calls and route change callbacks but these don't tell me anything about what's attached. They only report where the audio is currently routing. I need to know, for instance, if headphones and/or bluetooth are still attached while audio is routed through the speakers. Or, for instance, if a user plugs in the headset while using bluetooth then decides to disconnect bluetooth, I need to know that the bluetooth is disconnected even as audio is still routing through headphones.

推荐答案

在iOS 5中的情况下,你应该使用:

In case of iOS 5 you should use:

CFStringRef newRoute;
size = sizeof(CFStringRef);
XThrowIfError(AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &size, &newRoute), "couldn't get new audio route");
if (newRoute)
{
    CFShow(newRoute);
    if (CFStringCompare(newRoute, CFSTR("HeadsetInOut"), NULL) == kCFCompareEqualTo) // headset plugged in
          {
            colorLevels[0] = .3;                
            colorLevels[5] = .5;
          }
    else if (CFStringCompare(newRoute, CFSTR("SpeakerAndMicrophone"), NULL) == kCFCompareEqualTo)
}

这篇关于检测连接音频设备的iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆