一、AirPods Auto Switching
先看几张发布会截图。
AirPods现在可以在设备间无缝切换,无需手动操作。
比如:
- 你刚玩播客,拿起iPad打算看个电视节目,AirPods会神奇的切换过去;
- 之后你在Mac上开视频会议,AirPods会再一次自动切换过去;
- 如果有一通电话打进来,AirPods的音频会切换回手机。
二、支持的AirPods
// Apple官网注释
Works with AirPods Pro, AirPods (2nd generation), Powerbeats, Powerbeats Pro, and Beats Solo Pro. Requires an iCloud account, and iPhone or iPod with the latest version of iOS; iPad with the latest version of iPadOS; Apple Watch with the latest version of watchOS; or Mac with the latest version of macOS.
AutoMatic Switching需要的条件有:
- AirPods 2、AirPods Pro、Beats系列
- 需要同一个iCloud账户
- 最新版本的iOS、iPad OS、watchOS、Mac OS
可以看出,1代的AirPods是不支持这个特性的。对比1代和2代的配置信息,可以看出2者的主要差别在于W1芯片和H1芯片。
https://support.apple.com/kb/SP792?viewlocale=zh_CN&locale=zh_CN
https://support.apple.com/kb/SP750?viewlocale=zh_CN&locale=zh_CN
三、自动切换的原理
耳机如果要在设备间切换,目前我能够想到的有2种方法:
- 耳机支持多连接
- 根据场景自动路由
3.1 多连接
我个人有一个支持多设备连接的Bose耳机,能够同时连接几个设备,它的机制是这样的:
- 来电优先,来电能够跨设备抢占(猜测是BT SCO通道优先的原因)
- 媒体场景下,先来的抢占,后来的不发声(BT A2DP先到先得)
3.2 自动路由
目前苹果其实已经使用了这个技术,在iPhone、Apple Watch、AirPods上,无论是哪个设备来电,接听后,都会在AirPods发声。这次更新的AutoMatic Switching应该就是这个功能的扩展,把自动切换的设备从iPhone、Apple Watch,扩展到了iPad、Mac以及原有的设备。
3.3 AutoMatic Switching技术
仍然尝试在Apple官网上查找相关的技术,还真搜索到了一篇相关的。
AirPods Automatic Switching is a feature of Apple operating systems that intelligently connects wireless headphones to the most appropriate audio device in a multidevice environment. For example, if a user plays a movie on iPad, and then locks the device and starts playing music on iPhone, the system automatically switches the source audio device from iPad to iPhone.
iOS apps automatically participate in AirPods Automatic Switching. To enable your macOS app to participate in this behavior, use AVAudioRoutingArbiter to indicate when your app starts and finishes playing or recording audio. For example, a Voice over IP (VoIP) app might request arbitration before starting a call, and when the arbitration completes, begin the VoIP session. Likewise, when the call ends, the app would end the VoIP session and leave arbitration.
AirPods自动切换功能是Apple操作系统的一项功能,可以在多设备环境中将无线耳机智能地连接到最合适的音频设备。例如,如果用户在iPad上播放电影,然后锁定设备并开始在iPhone上播放音乐,则系统会自动将源音频设备从iPad切换到iPhone。
iOS应用程序自动参与AirPods自动切换。要使您的macOS应用程序参与此行为,请使用来指示您的应用程序何时开始和结束播放或录制音频。例如,IP语音(VoIP)应用程序可能在开始呼叫之前请求仲裁,并且在仲裁完成后,开始VoIP会话。同样,当呼叫结束时,该应用程序将结束VoIP会话并退出仲裁。
AVAudioRoutingArbiter的一个示例:
func startCall() {
let arbiter = AVAudioRoutingArbiter.shared
arbiter.begin(category: .playAndRecordVoice) { deviceChanged, error in
// Start VoIP session.
}
}
func endCall() {
// End VoIP session.
AVAudioRoutingArbiter.shared.leave()
}
如果对安卓的AudioFocus有一定了解的话,看到这里一定会觉得非常的熟悉。
应用在开始呼叫之前申请仲裁,在呼叫结束之后退出仲裁。这与安卓的AudioFocus不是一样的么?
应用程序在播放声音之前先申请音频焦点,应用使用完成之后,再丢弃音频焦点,应用可以抢占或者锁定音频焦点……参见我的另一篇文章:音频焦点 AudioFocus与Audio Log分析
四、疑问
对于音频焦点AudioFocus的管理,安卓是采用后来抢占、通话锁定的策略;对于Apple的AutoMatic Switching,不知道是如何管理设备间的冲突的。