在iPhone上选择音频设备 [英] Select Audio device on iPhone

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

问题描述

有没有办法让用户选择用于音频输出的设备?

Is there a way to let the user select which device they use for audio output?

在文档中我发现您可以通过将 kAudioSessionProperty_OverrideAudioRoute 设置为以下任一路径来选择:

In the docs I have found that you can select which route to use by setting kAudioSessionProperty_OverrideAudioRoute to either:


  • kAudioSessionOverrideAudioRoute_None,或

  • kAudioSessionOverrideAudioRoute_Speaker

但是我想让用户使用他们的蓝牙耳机听音频。

However I would like to let the user to use their Bluetooth headset to hear the audio.

如果您查看Apple自己的语音备忘录应用程序,在播放中菜单左上角有一个按钮,可让您选择要使用的音频设备。当连接蓝牙耳机时,按下按钮会弹出一个菜单,可以选择:

If you look in Apple's own 'Voice memos' app, in the playback menu there is a button in the top left which lets you choose which audio device to use. When a Bluetooth headset is attached, pressing the button brings up a menu which makes it possible to select between:


  • 蓝牙耳机

  • iPhone

  • 发言人

有没有办法实现这个目的在我自己的应用程序中使用标准Apple API的功能?

Is there a way to achieve this functionality using standard Apple APIs in my own app?

推荐答案

在3.1中,有两种协议支持将音频输出到蓝牙设备和使用取决于配件。第一个是A2DP,用于支持接收立体声音乐的存储,另一个是免提,适用于所有免提配件。
要激活第一个选项,您需要使用具有音量滑块和音频设备选择按钮的MPVolumeView类,当此视图添加到应用程序中的任何视图时,它为用户提供了一种方式设置音量并选择BT设备如果连接(这是我找到的唯一方法)
另一方面,第二个选项可以通过呼叫激活

In 3.1 there are two protocols that support outputting audio to bluetooth devices and the use depends on the accessory. The first is A2DP which is used with accessores that support recieving stereo music, and the other is hands free for all handfree accesories. To activate the first option, you need to use the MPVolumeView class which has a volume slider and a audio device selection button, when this view is added to any of the views in the app, it provides a way for the user to set the volume and select a BT device if connected ( this is the only way I found) On the other hand, the second option can be activated using the call

 UInt32 bt = TRUE;
 result = AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryEnableBluetoothInput , sizeof(UInt32), &bt);

应用程序必须初始化音频会话并使用corect catagory(它必须支持重新编码才能工作)。设置EnableBluetoothInput后,所有输入和输出音频将通过免提设备进行路由(如果连接当然:) :)

The appliction must initialize the audio session and use the corect catagory ( it must support recoding for this to work). After the EnableBluetoothInput is set all Input and output audio will be routed through the handsfree device ( if connected of course :) )

这篇关于在iPhone上选择音频设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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