From 8f5eb4499a584c829e5ddf1f9c737e2a9b9762b2 Mon Sep 17 00:00:00 2001 From: ThibaultBee <37510686+ThibaultBee@users.noreply.github.com> Date: Thu, 6 Jun 2024 16:05:35 +0200 Subject: [PATCH] fix(player): fix isMuted and volume API --- .../api/player/ApiVideoPlayerController.kt | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/player/src/main/java/video/api/player/ApiVideoPlayerController.kt b/player/src/main/java/video/api/player/ApiVideoPlayerController.kt index 5f7c391..7aad1f4 100644 --- a/player/src/main/java/video/api/player/ApiVideoPlayerController.kt +++ b/player/src/main/java/video/api/player/ApiVideoPlayerController.kt @@ -488,27 +488,34 @@ class ApiVideoPlayerController( } } + private var previousVolume = exoplayer.volume + /** - * Mutes/unmutes the device + * Mutes/unmutes the video */ var isMuted: Boolean /** - * Get the device mute states + * Get the mute states * - * @return true if the device is muted, false otherwise + * @return true if the video is muted, false otherwise */ - get() = exoplayer.isDeviceMuted + get() = volume == 0.0f /** - * Set the device mute states + * Set the mute states * - * @param value true if the device is muted, false otherwise + * @param value true if the video is muted, false otherwise */ set(value) { - exoplayer.setDeviceMuted(value, 0) + volume = if (value) { + previousVolume = volume + 0.0f + } else { + previousVolume + } } /** - * Gets/Sets the audio volume + * Gets/Sets the video volume */ var volume: Float /** @@ -516,17 +523,14 @@ class ApiVideoPlayerController( * * @return volume between 0 and 1.0 */ - get() = exoplayer.deviceVolume.toFloat() / (exoplayer.deviceInfo.maxVolume - exoplayer.deviceInfo.minVolume) - exoplayer.deviceInfo.minVolume + get() = exoplayer.volume /** * Set audio volume * * @param value volume between 0 and 1.0 */ set(value) { - exoplayer.setDeviceVolume( - (value * (exoplayer.deviceInfo.maxVolume - exoplayer.deviceInfo.minVolume) + exoplayer.deviceInfo.minVolume).toInt(), - 0 - ) + exoplayer.volume = value } /**