Skip to content

Commit 1444ca3

Browse files
committed
Align the implementation with what is done in Media3
1 parent 547570a commit 1444ca3

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

pillarbox-cast/src/main/java/ch/srgssr/pillarbox/cast/PillarboxCastPlayer.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ class PillarboxCastPlayer internal constructor(
202202
TrackSelectionParameters.DEFAULT
203203
}
204204
val deviceVolume = castSession?.let {
205-
(it.volume * MAX_VOLUME).roundToInt().coerceIn(VOLUME_RANGE)
205+
(it.volume * MAX_VOLUME).roundToInt().coerceIn(RANGE_DEVICE_VOLUME)
206206
}
207207

208208
return State.Builder()
@@ -317,14 +317,14 @@ class PillarboxCastPlayer internal constructor(
317317
}
318318

319319
override fun handleSetVolume(volume: Float) = withRemoteClient {
320-
setStreamVolume(volume.toDouble())
320+
setStreamVolume(volume.coerceIn(RANGE_VOLUME).toDouble())
321321
}
322322

323323
override fun handleSetDeviceVolume(
324324
@IntRange(from = 0) deviceVolume: Int,
325325
flags: @C.VolumeFlags Int,
326326
) = withCastSession("handleSetDeviceVolume") {
327-
volume = deviceVolume.coerceIn(VOLUME_RANGE) / MAX_VOLUME.toDouble()
327+
volume = deviceVolume.coerceIn(RANGE_DEVICE_VOLUME) / MAX_VOLUME.toDouble()
328328
}
329329

330330
override fun handleIncreaseDeviceVolume(flags: @C.VolumeFlags Int): ListenableFuture<*> {
@@ -661,7 +661,8 @@ class PillarboxCastPlayer internal constructor(
661661
.setMaxVolume(MAX_VOLUME)
662662
.build()
663663

664-
private val VOLUME_RANGE = 0..MAX_VOLUME
664+
private val RANGE_DEVICE_VOLUME = 0..MAX_VOLUME
665+
private val RANGE_VOLUME = 0f..1f
665666

666667
private fun createTrackSelectionParametersFromSelectedTracks(tracks: Tracks): TrackSelectionParameters {
667668
return TrackSelectionParameters.DEFAULT.buildUpon().apply {

pillarbox-cast/src/main/java/ch/srgssr/pillarbox/cast/extension/RemoteMediaClient.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ internal fun RemoteMediaClient.getRepeatMode(): @Player.RepeatMode Int {
104104
}
105105

106106
internal fun RemoteMediaClient.getVolume(): Double {
107-
return mediaStatus?.streamVolume ?: 0.0
107+
return mediaStatus?.streamVolume ?: 1.0
108108
}
109109

110110
internal fun RemoteMediaClient.getTracks(): Tracks {

pillarbox-cast/src/test/java/ch/srgssr/pillarbox/cast/extension/RemoteMediaClientTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class RemoteMediaClientTest {
158158
@Test
159159
fun `getVolume returns 0 when mediaStatus is null`() {
160160
every { remoteMediaClient.mediaStatus } returns null
161-
assertEquals(0.0, remoteMediaClient.getVolume())
161+
assertEquals(1.0, remoteMediaClient.getVolume())
162162
}
163163

164164
@Test

pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/utils/StringUtil.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ object StringUtil {
9292
fun playerCommandsString(value: Player.Commands): String {
9393
return buildList {
9494
repeat(value.size()) {
95+
@Suppress("deprecation")
9596
val commandName = when (val command = value.get(it)) {
9697
Player.COMMAND_INVALID -> "COMMAND_INVALID"
9798
Player.COMMAND_PLAY_PAUSE -> "COMMAND_PLAY_PAUSE"

0 commit comments

Comments
 (0)