[英]iOS 7 Get all the available audio devices (bluetooth, headset, speaker, phone)
Desired feature: 期望的功能:
It's something like iPhone native phone app. 这就像iPhone本机手机应用程序。 When there are bluetooth/headset connected to iPhone, the speaker button (usually only speaker/phone toggle) will show you all the available audio output devices. 当蓝牙/耳机连接到iPhone时,扬声器按钮(通常只有扬声器/电话切换)将显示所有可用的音频输出设备。 Default using Bluetooth. 默认使用蓝牙。 User can select another device to play the sound. 用户可以选择其他设备播放声音。
Problem: 问题:
How can I detect all the available audio devices connected to an iPhone? 如何检测连接到iPhone的所有可用音频设备?
How can I update the route and set audio output to selected device? 如何更新路由并将音频输出设置为所选设备?
Note that existing solution with AudioSessionGetProperty AND AudioSessionSetProperty may not be ideal because these two methods are deprecated from iOS7. 请注意,使用AudioSessionGetProperty和AudioSessionSetProperty的现有解决方案可能并不理想,因为iOS7不推荐使用这两种方法。
Since no response. 既然没有回应。 I started to write my own library based on Jawbone's AudioSessionManager. 我开始基于Jawbone的AudioSessionManager编写自己的库。
Regarding the two problems 关于这两个问题
I still can't find ways to get available outputs. 我仍然找不到获得可用输出的方法。 but AVAudioSession do supports property availableInputs from iOS7. 但是AVAudioSession确实支持来自iOS7的属性availableInputs。
AVAudioSession has a routeChange notification. AVAudioSession有一个routeChange通知。 you can catch different route change reason and handle it properly. 你可以捕捉到不同的路线变化原因并妥善处理。
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(currentRouteChanged:) name:AVAudioSessionRouteChangeNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(currentRouteChanged :) name:AVAudioSessionRouteChangeNotification object:nil];
The full implementation is in my github repo . 完整的实现是在我的github 回购 。 Feedback is welcomed. 欢迎反馈。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.