简体   繁体   中英

iOS 7 Get all the available audio devices (bluetooth, headset, speaker, phone)

Desired feature:

It's something like iPhone native phone app. 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. Default using Bluetooth. User can select another device to play the sound.

Problem:

  1. How can I detect all the available audio devices connected to an iPhone?

  2. 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.

Since no response. I started to write my own library based on Jawbone's AudioSessionManager.

Regarding the two problems

  1. I still can't find ways to get available outputs. but AVAudioSession do supports property availableInputs from iOS7.

  2. AVAudioSession has a routeChange notification. you can catch different route change reason and handle it properly.

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(currentRouteChanged:) name:AVAudioSessionRouteChangeNotification object:nil];

The full implementation is in my github repo . Feedback is welcomed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM