AudioSwitch

fun AudioSwitch(context: Context, bluetoothHeadsetConnectionListener: BluetoothHeadsetConnectionListener? = null, loggingEnabled: Boolean = false, audioFocusChangeListener: AudioManager.OnAudioFocusChangeListener = OnAudioFocusChangeListener {}, preferredDeviceList: List<Class<out AudioDevice>> = defaultPreferredDeviceList)

Constructs a new AudioSwitch instance.

  • context - An Android Context.

  • bluetoothHeadsetConnectionListener - A listener to notify if Bluetooth device state has changed (connect, disconnect, audio connect, audio disconnect) or failed to connect. Null by default

  • loggingEnabled - Toggle whether logging is enabled. This argument is false by default.

  • audioFocusChangeListener - A listener that is invoked when the system audio focus is updated. Note that updates are only sent to the listener after activate has been called.

  • preferredDeviceList - The order in which AudioSwitch automatically selects and activates an AudioDevice. This parameter is ignored if the selectedAudioDevice is not null. The default preferred AudioDevice order is the following: BluetoothHeadset, WiredHeadset, Earpiece, Speakerphone . The preferredDeviceList is added to the front of the default list. For example, if preferredDeviceList is Speakerphone and BluetoothHeadset, then the new preferred audio device list will be: Speakerphone, BluetoothHeadset, WiredHeadset, Earpiece. An IllegalArgumentException is thrown if the preferredDeviceList contains duplicate AudioDevice elements.