Skip to content

Commit

Permalink
Speakerphone fallback update (#1051)
Browse files Browse the repository at this point in the history
* Disable speakerphone when enabling microphone

* When the speakerphone is disabled allow for the API to set preference which device is next

* Fix typo
  • Loading branch information
aleksandar-apostolov authored Apr 1, 2024
1 parent 3b63874 commit c8429f8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
3 changes: 2 additions & 1 deletion stream-video-android-core/api/stream-video-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,8 @@ public final class io/getstream/video/android/core/SpeakerManager {
public final fun resume ()V
public final fun setEnabled (ZZ)V
public static synthetic fun setEnabled$default (Lio/getstream/video/android/core/SpeakerManager;ZZILjava/lang/Object;)V
public final fun setSpeakerPhone (Z)V
public final fun setSpeakerPhone (ZLio/getstream/video/android/core/audio/StreamAudioDevice;)V
public static synthetic fun setSpeakerPhone$default (Lio/getstream/video/android/core/SpeakerManager;ZLio/getstream/video/android/core/audio/StreamAudioDevice;ILjava/lang/Object;)V
public final fun setVolume (I)V
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,20 @@ class SpeakerManager(
}
}

/** enables or disables the speakerphone */
fun setSpeakerPhone(enable: Boolean) {
/**
* 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
* ```kotlin
* setSpeakerPhone(enable, StreamAudioDevice.Earpiece)
* ```
*
* @param enable if true, enables the speakerphone, if false disables it and selects another device.
* @param defaultFallback when [enable] is false this is used to select the next device after the speaker.
* */
fun setSpeakerPhone(enable: Boolean, defaultFallback: StreamAudioDevice? = null) {
microphoneManager.setup()
val devices = devices.value
if (enable) {
Expand All @@ -134,9 +146,12 @@ class SpeakerManager(
} else {
_speakerPhoneEnabled.value = false
// swap back to the old one
val fallback =
selectedBeforeSpeaker
?: devices.firstOrNull { it !is StreamAudioDevice.Speakerphone }
val defaultFallbackFromType = defaultFallback?.let {
devices.filterIsInstance(defaultFallback::class.java)
}?.firstOrNull()
val fallback = defaultFallbackFromType ?: selectedBeforeSpeaker ?: devices.firstOrNull {
it !is StreamAudioDevice.Speakerphone
}
microphoneManager.select(fallback)
}
}
Expand Down

0 comments on commit c8429f8

Please sign in to comment.