Skip to content

Commit

Permalink
fix(player): fix isMuted and volume API
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibaultBee committed Jun 6, 2024
1 parent e9b3133 commit 8f5eb44
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions player/src/main/java/video/api/player/ApiVideoPlayerController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -488,45 +488,49 @@ 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
/**
* Get audio volume
*
* @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
}

/**
Expand Down

0 comments on commit 8f5eb44

Please sign in to comment.