Audio Output Routing

These are android only APIs. Audio Routing can be helpful in the case when user wants to switch output to device other than the default focussed one by SDK.

Switch audio focus to another device

fun switchAudioOutput(audioDevice: HMSAudioDevice)

Types of audio routing supported.

  • SPEAKER - route audio to device speaker
  • EARPIECE - route audio to device earpiece
  • WIRED - route audio to connected wired device
  • BLUETOOTH - route audio to connected bluetooth device
  • AUTOMATIC - automatic routing

invoke this method with appropriate option , to switch the output to that device

audioDevice is the [AudioDevice] type through which audio should be routed.

import { HMSAudioDevice } from '@100mslive/react-native-hms'; hmsInstance?.switchAudioOutput(HMSAudioDevice.EARPIECE)

Adding a listener

fun setAudioDeviceChangeListener(callback: Function)

Add a listener to get updates whenever a device is removed or attached to the device. Callback function to be passed to be able to listen to device updates.

Callback methods :

  • callback passed - this method is invoked when output device has changed.
  • onError listener - this method is invoked when there is an error with switching to output device.
const onAudioDeviceChangedListener = (data: { device: string; audioDevicesList: string[]; }) => { // }; hmsInstance?.setAudioDeviceChangeListener(onAudioDeviceChangedListener)

Get current focussed device

async function getAudioOutputRouteType() : AudioDevice

invoke this method get current device type through which audio output is being routed.

await hmsInstance?.getAudioOutputRouteType()

Get list of audio device

async function getAudioDevicesList() : AudioDevice[]

invoke this method get list of devices type through which audio output can be routed.

await hmsInstance?.getAudioDevicesList()