-
public final class SpeakerManager
-
-
Field Summary
Fields Modifier and Type Field Description private final StateFlow<Integer>volumeprivate final StateFlow<DeviceStatus>statusprivate final StateFlow<Boolean>isEnabledprivate final StateFlow<Integer>audioUsageprivate final StateFlow<StreamAudioDevice>selectedDeviceprivate final StateFlow<List<StreamAudioDevice>>devicesprivate final StateFlow<Boolean>speakerPhoneEnabledprivate final MediaManagerImplmediaManagerprivate final MicrophoneManagermicrophoneManagerprivate final IntegerinitialVolumeprivate final Function0<Integer>audioUsageProvider
-
Constructor Summary
Constructors Constructor Description SpeakerManager(MediaManagerImpl mediaManager, MicrophoneManager microphoneManager, Integer initialVolume, Function0<Integer> audioUsageProvider)
-
Method Summary
Modifier and Type Method Description final StateFlow<Integer>getVolume()final StateFlow<DeviceStatus>getStatus()final StateFlow<Boolean>getIsEnabled()Represents whether the speakerphone is enabled final StateFlow<Integer>getAudioUsage()final StateFlow<StreamAudioDevice>getSelectedDevice()final StateFlow<List<StreamAudioDevice>>getDevices()final StateFlow<Boolean>getSpeakerPhoneEnabled()final MediaManagerImplgetMediaManager()final MicrophoneManagergetMicrophoneManager()final IntegergetInitialVolume()final Function0<Integer>getAudioUsageProvider()final Unitdisable(Boolean fromUser)final UnitsetEnabled(Boolean enabled, Boolean fromUser)Enable or disable the speakerphone. final UnitsetSpeakerPhone(Boolean enable, StreamAudioDevice defaultFallback)Enables or disables the speakerphone. final UnitsetVolume(Integer volumePercentage)Set the volume as a percentage, 0-100 final Unitpause()final Unitresume()final BooleansetAudioUsage(Integer audioUsage)Set the audio usage value. -
-
Constructor Detail
-
SpeakerManager
SpeakerManager(MediaManagerImpl mediaManager, MicrophoneManager microphoneManager, Integer initialVolume, Function0<Integer> audioUsageProvider)
-
-
Method Detail
-
getStatus
final StateFlow<DeviceStatus> getStatus()
-
getIsEnabled
final StateFlow<Boolean> getIsEnabled()
Represents whether the speakerphone is enabled
-
getAudioUsage
final StateFlow<Integer> getAudioUsage()
-
getSelectedDevice
final StateFlow<StreamAudioDevice> getSelectedDevice()
-
getDevices
final StateFlow<List<StreamAudioDevice>> getDevices()
-
getSpeakerPhoneEnabled
final StateFlow<Boolean> getSpeakerPhoneEnabled()
-
getMediaManager
final MediaManagerImpl getMediaManager()
-
getMicrophoneManager
final MicrophoneManager getMicrophoneManager()
-
getInitialVolume
final Integer getInitialVolume()
-
getAudioUsageProvider
final Function0<Integer> getAudioUsageProvider()
-
setEnabled
final Unit setEnabled(Boolean enabled, Boolean fromUser)
Enable or disable the speakerphone.
-
setSpeakerPhone
final Unit setSpeakerPhone(Boolean enable, StreamAudioDevice defaultFallback)
Enables or disables the speakerphone.
When the speaker is disabled the device that gets selected next is by default the first device that is NOT a speakerphone. To override this use defaultFallback. If you want the earpice to be selected if the speakerphone is disabled do
setSpeakerPhone(enable, StreamAudioDevice.Earpiece)- Parameters:
enable- if true, enables the speakerphone, if false disables it and selects another device.defaultFallback- when enable is false this is used to select the next device after the speaker.
-
setAudioUsage
final Boolean setAudioUsage(Integer audioUsage)
Set the audio usage value. This allows toggling between USAGE_MEDIA and USAGE_VOICE_COMMUNICATION. Updates the StateFlow immediately for responsive UI, then attempts to update the ADM. If the ADM update fails, the StateFlow is rolled back to the previous value.
- Parameters:
audioUsage- The audio usage value to set (e.g., AudioAttributes.USAGE_MEDIA or AudioAttributes.
-
-
-
-