Is there a way to access pins like availableInputs in AVAudioSession

I need to list the available outputs (e.g. BleutoothLE, HeadPhones, BuiltInReceiver), but I can just access the current output.

Can anyone access all available exits, please share comments?

Thanks in advance.

+6
source share
3 answers

I have two options:

  • Add an MPVolumeView to your view and set the showsVolumeSlider parameter to 0 and set showsRouteButton to 1. This will result in a system icon that the user can select from the available outputs.

  • AVAudioSession has a very limited overrideOutputAudioPort method that can redirect sound to the built-in speaker.

     [[AVAudioSession sharedInstance] overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:nil]; 
+3
source

I do not know why there was no simple property availableOutputs .

But you can get a list of all available outputs using the multi-pass audio category and check your current route outputs:

 let sesh = AVAudioSession() try! sesh.setCategory(AVAudioSessionCategoryMultiRoute) try! sesh.setActive(true) print("available outputs: \(sesh.currentRoute.outputs)\n") 

Exits (and inputs) come and go, causing changes in the route, so sign up for a notification of a change in the route:

 NSNotificationCenter.defaultCenter().addObserver( self, selector: "routeChanged:", name: AVAudioSessionRouteChangeNotification, object:nil ) 

NB : in the multi-route category, there are a lot of rules about when the inputs / outputs that are available on an intuitive level are actually available (for example, the speaker is not available "if you have a USB sound card installed, but wired headphones will be) .

What are you trying to do? I used a multi-pass channel to play 4-channel audio, but I'm not sure if you can actually mix and match the outputs.

0
source

Get a list of all results using AVAudioSession currentRoute :

 AVAudioSession *session = [AVAudioSession sharedInstance]; NSLog(@"Outputs: %@", [[session currentRoute] outputs]); 
-1
source

All Articles