-
- All Implemented Interfaces:
-
io.livekit.android.audio.AudioHandler
@Singleton() public final class AudioSwitchHandler implements AudioHandler
An AudioHandler built on top of AudioSwitch. This handles things such as getting the audio focus as needed, as well as automatic audio output device management.
The various settings should be set before connecting to a Room and start is called.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classAudioSwitchHandler.Companion
-
Field Summary
Fields Modifier and Type Field Description private BooleanloggingEnabledprivate <ERROR CLASS>audioDeviceChangeListenerprivate AudioManager.OnAudioFocusChangeListeneronAudioFocusChangeListenerprivate List<Class<out AudioDevice>>preferredDeviceListprivate BooleanmanageAudioFocusprivate IntegeraudioModeprivate IntegerfocusModeprivate IntegeraudioStreamTypeprivate IntegeraudioAttributeUsageTypeprivate IntegeraudioAttributeContentTypeprivate BooleanforceHandleAudioRoutingprivate final AudioDeviceselectedAudioDeviceprivate final List<AudioDevice>availableAudioDevices
-
Constructor Summary
Constructors Constructor Description AudioSwitchHandler(Context context)
-
Method Summary
Modifier and Type Method Description final BooleangetLoggingEnabled()Toggle whether logging is enabled for AudioSwitch. final UnitsetLoggingEnabled(Boolean loggingEnabled)Toggle whether logging is enabled for AudioSwitch. final <ERROR CLASS>getAudioDeviceChangeListener()Listen to changes in the available and active audio devices. final Unit)>setAudioDeviceChangeListener(@Deprecated(message = Use registerAudioDeviceChangeListener.) <ERROR CLASS> audioDeviceChangeListener)Listen to changes in the available and active audio devices. final AudioManager.OnAudioFocusChangeListenergetOnAudioFocusChangeListener()Listen to changes in audio focus. final UnitsetOnAudioFocusChangeListener(@Deprecated(message = Use registerOnAudioFocusChangeListener.) AudioManager.OnAudioFocusChangeListener onAudioFocusChangeListener)Listen to changes in audio focus. final List<Class<out AudioDevice>>getPreferredDeviceList()final UnitsetPreferredDeviceList(List<Class<out AudioDevice>> preferredDeviceList)final BooleangetManageAudioFocus()When true, AudioSwitchHandler will request audio focus on start and abandon on stop. final UnitsetManageAudioFocus(Boolean manageAudioFocus)When true, AudioSwitchHandler will request audio focus on start and abandon on stop. final IntegergetAudioMode()The audio mode to use when requesting audio focus. final UnitsetAudioMode(Integer audioMode)The audio mode to use when requesting audio focus. final IntegergetFocusMode()The audio focus mode to use while started. final UnitsetFocusMode(Integer focusMode)The audio focus mode to use while started. final IntegergetAudioStreamType()The audio stream type to use when requesting audio focus on pre-O devices. final UnitsetAudioStreamType(Integer audioStreamType)The audio stream type to use when requesting audio focus on pre-O devices. final IntegergetAudioAttributeUsageType()The audio attribute usage type to use when requesting audio focus on devices O and beyond. final UnitsetAudioAttributeUsageType(Integer audioAttributeUsageType)The audio attribute usage type to use when requesting audio focus on devices O and beyond. final IntegergetAudioAttributeContentType()The audio attribute content type to use when requesting audio focus on devices O and beyond. final UnitsetAudioAttributeContentType(Integer audioAttributeContentType)The audio attribute content type to use when requesting audio focus on devices O and beyond. final BooleangetForceHandleAudioRouting()On certain Android devices, audio routing does not function properly and bluetooth microphones will not work unless audio mode is set to AudioManager.MODE_IN_COMMUNICATION or AudioManager.MODE_IN_CALL. final UnitsetForceHandleAudioRouting(Boolean forceHandleAudioRouting)On certain Android devices, audio routing does not function properly and bluetooth microphones will not work unless audio mode is set to AudioManager.MODE_IN_COMMUNICATION or AudioManager.MODE_IN_CALL. final AudioDevicegetSelectedAudioDevice()final List<AudioDevice>getAvailableAudioDevices()Unitstart()Called when a room is started. Unitstop()Called when a room is disconnected. final UnitselectDevice(AudioDevice audioDevice)Select a specific audio device. final Unit)>registerAudioDeviceChangeListener(<ERROR CLASS> listener)Listen to changes in the available and active audio devices. final Unit)>unregisterAudioDeviceChangeListener(<ERROR CLASS> listener)Remove a previously registered audio device change listener. final UnitregisterOnAudioFocusChangeListener(AudioManager.OnAudioFocusChangeListener listener)Listen to changes in audio focus. final UnitunregisterOnAudioFocusChangeListener(AudioManager.OnAudioFocusChangeListener listener)Remove a previously registered focus change listener. -
-
Constructor Detail
-
AudioSwitchHandler
AudioSwitchHandler(Context context)
-
-
Method Detail
-
getLoggingEnabled
final Boolean getLoggingEnabled()
Toggle whether logging is enabled for AudioSwitch. By default, this is set to false.
-
setLoggingEnabled
final Unit setLoggingEnabled(Boolean loggingEnabled)
Toggle whether logging is enabled for AudioSwitch. By default, this is set to false.
-
getAudioDeviceChangeListener
final <ERROR CLASS> getAudioDeviceChangeListener()
Listen to changes in the available and active audio devices.
-
setAudioDeviceChangeListener
final Unit )>setAudioDeviceChangeListener(@Deprecated(message = Use registerAudioDeviceChangeListener.) <ERROR CLASS> audioDeviceChangeListener)
Listen to changes in the available and active audio devices.
-
getOnAudioFocusChangeListener
final AudioManager.OnAudioFocusChangeListener getOnAudioFocusChangeListener()
Listen to changes in audio focus.
-
setOnAudioFocusChangeListener
final Unit setOnAudioFocusChangeListener(@Deprecated(message = Use registerOnAudioFocusChangeListener.) AudioManager.OnAudioFocusChangeListener onAudioFocusChangeListener)
Listen to changes in audio focus.
-
getPreferredDeviceList
final List<Class<out AudioDevice>> getPreferredDeviceList()
-
setPreferredDeviceList
final Unit setPreferredDeviceList(List<Class<out AudioDevice>> preferredDeviceList)
-
getManageAudioFocus
final Boolean getManageAudioFocus()
When true, AudioSwitchHandler will request audio focus on start and abandon on stop.
Defaults to true.
-
setManageAudioFocus
final Unit setManageAudioFocus(Boolean manageAudioFocus)
When true, AudioSwitchHandler will request audio focus on start and abandon on stop.
Defaults to true.
-
getAudioMode
final Integer getAudioMode()
The audio mode to use when requesting audio focus.
Defaults to AudioManager.MODE_IN_COMMUNICATION.
Note: Manual audio routing may not work appropriately when using non-default values.
-
setAudioMode
final Unit setAudioMode(Integer audioMode)
The audio mode to use when requesting audio focus.
Defaults to AudioManager.MODE_IN_COMMUNICATION.
Note: Manual audio routing may not work appropriately when using non-default values.
-
getFocusMode
final Integer getFocusMode()
The audio focus mode to use while started.
Defaults to AudioManager.AUDIOFOCUS_GAIN.
-
setFocusMode
final Unit setFocusMode(Integer focusMode)
The audio focus mode to use while started.
Defaults to AudioManager.AUDIOFOCUS_GAIN.
-
getAudioStreamType
final Integer getAudioStreamType()
The audio stream type to use when requesting audio focus on pre-O devices.
Defaults to AudioManager.STREAM_VOICE_CALL.
Refer to this compatibility table to ensure that your values match between android versions.
Note: Manual audio routing may not work appropriately when using non-default values.
-
setAudioStreamType
final Unit setAudioStreamType(Integer audioStreamType)
The audio stream type to use when requesting audio focus on pre-O devices.
Defaults to AudioManager.STREAM_VOICE_CALL.
Refer to this compatibility table to ensure that your values match between android versions.
Note: Manual audio routing may not work appropriately when using non-default values.
-
getAudioAttributeUsageType
final Integer getAudioAttributeUsageType()
The audio attribute usage type to use when requesting audio focus on devices O and beyond.
Defaults to AudioAttributes.USAGE_VOICE_COMMUNICATION.
Refer to this compatibility table to ensure that your values match between android versions.
Note: Manual audio routing may not work appropriately when using non-default values.
-
setAudioAttributeUsageType
final Unit setAudioAttributeUsageType(Integer audioAttributeUsageType)
The audio attribute usage type to use when requesting audio focus on devices O and beyond.
Defaults to AudioAttributes.USAGE_VOICE_COMMUNICATION.
Refer to this compatibility table to ensure that your values match between android versions.
Note: Manual audio routing may not work appropriately when using non-default values.
-
getAudioAttributeContentType
final Integer getAudioAttributeContentType()
The audio attribute content type to use when requesting audio focus on devices O and beyond.
Defaults to AudioAttributes.CONTENT_TYPE_SPEECH.
Refer to this compatibility table to ensure that your values match between android versions.
Note: Manual audio routing may not work appropriately when using non-default values.
-
setAudioAttributeContentType
final Unit setAudioAttributeContentType(Integer audioAttributeContentType)
The audio attribute content type to use when requesting audio focus on devices O and beyond.
Defaults to AudioAttributes.CONTENT_TYPE_SPEECH.
Refer to this compatibility table to ensure that your values match between android versions.
Note: Manual audio routing may not work appropriately when using non-default values.
-
getForceHandleAudioRouting
final Boolean getForceHandleAudioRouting()
On certain Android devices, audio routing does not function properly and bluetooth microphones will not work unless audio mode is set to AudioManager.MODE_IN_COMMUNICATION or AudioManager.MODE_IN_CALL.
AudioSwitchHandler by default will not handle audio routing in those cases to avoid audio issues.
If this set to true, AudioSwitchHandler will attempt to do audio routing, though behavior is undefined.
-
setForceHandleAudioRouting
final Unit setForceHandleAudioRouting(Boolean forceHandleAudioRouting)
On certain Android devices, audio routing does not function properly and bluetooth microphones will not work unless audio mode is set to AudioManager.MODE_IN_COMMUNICATION or AudioManager.MODE_IN_CALL.
AudioSwitchHandler by default will not handle audio routing in those cases to avoid audio issues.
If this set to true, AudioSwitchHandler will attempt to do audio routing, though behavior is undefined.
-
getSelectedAudioDevice
final AudioDevice getSelectedAudioDevice()
-
getAvailableAudioDevices
final List<AudioDevice> getAvailableAudioDevices()
-
start
@Synchronized() Unit start()
Called when a room is started.
-
stop
@Synchronized() Unit stop()
Called when a room is disconnected.
-
selectDevice
@Synchronized() final Unit selectDevice(AudioDevice audioDevice)
Select a specific audio device.
-
registerAudioDeviceChangeListener
final Unit )>registerAudioDeviceChangeListener(<ERROR CLASS> listener)
Listen to changes in the available and active audio devices.
-
unregisterAudioDeviceChangeListener
final Unit )>unregisterAudioDeviceChangeListener(<ERROR CLASS> listener)
Remove a previously registered audio device change listener.
-
registerOnAudioFocusChangeListener
final Unit registerOnAudioFocusChangeListener(AudioManager.OnAudioFocusChangeListener listener)
Listen to changes in audio focus.
-
unregisterOnAudioFocusChangeListener
final Unit unregisterOnAudioFocusChangeListener(AudioManager.OnAudioFocusChangeListener listener)
Remove a previously registered focus change listener.
-
-
-
-