-
public final class MicrophoneManagerThe Microphone manager makes it easy to use your microphone in a call
-
-
Field Summary
Fields Modifier and Type Field Description private final StateFlow<List<UsbAudioInputDevice>>usbInputDevicesprivate final StateFlow<UsbAudioInputDevice>selectedUsbDeviceprivate final StateFlow<DeviceStatus>statusprivate final StateFlow<Boolean>isEnabledprivate final StateFlow<StreamAudioDevice>selectedDeviceprivate final StateFlow<List<StreamAudioDevice>>devicesprivate final StateFlow<AudioBitrateProfile>audioBitrateProfileprivate final MediaManagerImplmediaManagerprivate final IntegeraudioUsageprivate final Function0<Integer>audioUsageProvider
-
Constructor Summary
Constructors Constructor Description MicrophoneManager(MediaManagerImpl mediaManager, Integer audioUsage, Function0<Integer> audioUsageProvider)
-
Method Summary
Modifier and Type Method Description final StateFlow<List<UsbAudioInputDevice>>getUsbInputDevices()List of detected USB audio input devices. final StateFlow<UsbAudioInputDevice>getSelectedUsbDevice()The currently selected USB input device, or null if using default routing. final StateFlow<DeviceStatus>getStatus()The status of the audio final StateFlow<Boolean>getIsEnabled()Represents whether the audio is enabled final StateFlow<StreamAudioDevice>getSelectedDevice()Currently selected device final StateFlow<List<StreamAudioDevice>>getDevices()List of available devices. final StateFlow<AudioBitrateProfile>getAudioBitrateProfile()The audio bitrate profile currently in force — observe this to drive a music/voice toggle. final MediaManagerImplgetMediaManager()final IntegergetAudioUsage()final Function0<Integer>getAudioUsageProvider()final Unitpause(Boolean fromUser)final Unitresume(Boolean fromUser)final Unitdisable(Boolean fromUser)Disable the audio track. final UnitsetEnabled(Boolean enabled, Boolean fromUser)Enable or disable the microphone final Unitselect(StreamAudioDevice device)Select a specific device final StateFlow<List<StreamAudioDevice>>listDevices()List the devices, returns a stateflow with audio devices final UnitsetupUsbDeviceDetection()Sets up USB audio device detection using Android's AudioDeviceCallback. final BooleanselectUsbDevice(UsbAudioInputDevice device)Selects a USB input device as the preferred audio input source. final UnitclearUsbDeviceSelection()Clears the USB device selection, restoring default audio routing. final StateFlow<List<UsbAudioInputDevice>>listUsbDevices()Lists all detected USB input devices. final Result<Unit>setAudioBitrateProfile(AudioBitrateProfile profile)Sets the audio bitrate profile, before joining or on a running call, so a broadcaster who starts playing music can switch to MUSIC_HIGH_QUALITY without rejoining. final Unitcleanup()final BooleancanHandleDeviceSwitch()-
-
Constructor Detail
-
MicrophoneManager
MicrophoneManager(MediaManagerImpl mediaManager, Integer audioUsage, Function0<Integer> audioUsageProvider)
-
-
Method Detail
-
getUsbInputDevices
final StateFlow<List<UsbAudioInputDevice>> getUsbInputDevices()
List of detected USB audio input devices.
These devices are detected using Android's AudioDeviceCallback API and include USB microphones that may not appear in devices because AudioSwitch only detects devices with both input and output capabilities.
Requires Android M (API 23) or higher.
-
getSelectedUsbDevice
final StateFlow<UsbAudioInputDevice> getSelectedUsbDevice()
The currently selected USB input device, or null if using default routing.
-
getStatus
final StateFlow<DeviceStatus> getStatus()
The status of the audio
-
getIsEnabled
final StateFlow<Boolean> getIsEnabled()
Represents whether the audio is enabled
-
getSelectedDevice
final StateFlow<StreamAudioDevice> getSelectedDevice()
Currently selected device
-
getDevices
final StateFlow<List<StreamAudioDevice>> getDevices()
List of available devices.
-
getAudioBitrateProfile
final StateFlow<AudioBitrateProfile> getAudioBitrateProfile()
The audio bitrate profile currently in force — observe this to drive a music/voice toggle.
Only moves when the profile actually took. Set before joining it always does, since the pipeline is then built from it. On a running call it moves only if every reachable stage accepted the change; otherwise it keeps reporting the previous profile, so a toggle bound to it snaps back rather than claiming a switch the audio did not make, and setAudioBitrateProfile fails naming the stages that refused.
-
getMediaManager
final MediaManagerImpl getMediaManager()
-
getAudioUsage
final Integer getAudioUsage()
-
getAudioUsageProvider
final Function0<Integer> getAudioUsageProvider()
-
disable
final Unit disable(Boolean fromUser)
Disable the audio track. Audio is still captured, but not send. This allows for the "you are muted" toast to indicate you are talking while muted
-
setEnabled
final Unit setEnabled(Boolean enabled, Boolean fromUser)
Enable or disable the microphone
-
select
final Unit select(StreamAudioDevice device)
Select a specific device
-
listDevices
final StateFlow<List<StreamAudioDevice>> listDevices()
List the devices, returns a stateflow with audio devices
-
setupUsbDeviceDetection
final Unit setupUsbDeviceDetection()
Sets up USB audio device detection using Android's AudioDeviceCallback.
This detects USB input devices (microphones), such as the Rode Wireless Go II and other professional USB microphones.
Requires Android M (API 23) or higher.
-
selectUsbDevice
final Boolean selectUsbDevice(UsbAudioInputDevice device)
Selects a USB input device as the preferred audio input source.
This routes audio recording to the specified USB device, bypassing AudioSwitch's default device selection. Use this for USB microphones that don't appear in devices.
- Parameters:
device- The USB device to use, or null to restore default routing.
-
clearUsbDeviceSelection
final Unit clearUsbDeviceSelection()
Clears the USB device selection, restoring default audio routing.
Resets the state directly rather than going through selectUsbDevice with null, because the WebRTC ADM's setPreferredInputDevice does not accept null safely. When the USB device is physically removed, the system automatically falls back to default audio routing, so an explicit ADM call is unnecessary.
-
listUsbDevices
final StateFlow<List<UsbAudioInputDevice>> listUsbDevices()
Lists all detected USB input devices.
-
setAudioBitrateProfile
final Result<Unit> setAudioBitrateProfile(AudioBitrateProfile profile)
Sets the audio bitrate profile, before joining or on a running call, so a broadcaster who starts playing music can switch to MUSIC_HIGH_QUALITY without rejoining.
Requires HiFi audio enabled in the dashboard settings. The Opus bitrate and channel count come from the server at join, so a mid-call switch does not renegotiate them.
Expect a brief gap in captured audio on a mid-call switch: the platform rebuilds its capture path. The call is not interrupted otherwise.
Echo cancellation goes off under MUSIC_HIGH_QUALITY, so treat music as a headphones setting. It also costs communication routing and Bluetooth capture — SCO only runs in communication mode.
Read the profile in force back from audioBitrateProfile.
-
canHandleDeviceSwitch
final Boolean canHandleDeviceSwitch()
-
-
-
-