Skip to content

Commit ae37f1c

Browse files
committed
Address internal review comments
1 parent 5293d6a commit ae37f1c

File tree

2 files changed

+10
-27
lines changed

2 files changed

+10
-27
lines changed

libraries/cast/src/main/java/androidx/media3/cast/CastPlayer.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ public final class CastPlayer extends BasePlayer {
113113
public static final DeviceInfo DEVICE_INFO_REMOTE_EMPTY =
114114
new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_REMOTE).setMaxVolume(MAX_VOLUME).build();
115115

116-
private static final Range<Integer> VOLUME_RANGE = new Range<>(0, MAX_VOLUME);
116+
private static final Range<Integer> RANGE_DEVICE_VOLUME = new Range<>(0, MAX_VOLUME);
117+
private static final Range<Float> RANGE_VOLUME = new Range<>(0.f, 1.f);
117118

118119
static {
119120
MediaLibraryInfo.registerModule("media3.cast");
@@ -791,6 +792,7 @@ public void setVolume(float volume) {
791792
// We update the local state and send the message to the receiver app, which will cause the
792793
// operation to be perceived as synchronous by the user. When the operation reports a result,
793794
// the local state will be updated to reflect the state reported by the Cast SDK.
795+
volume = RANGE_VOLUME.clamp(volume);
794796
setVolumeAndNotifyIfChanged(volume);
795797
listeners.flushEvents();
796798
PendingResult<MediaChannelResult> pendingResult = remoteMediaClient.setStreamVolume(volume);
@@ -901,7 +903,7 @@ public void setDeviceVolume(@IntRange(from = 0) int volume, @C.VolumeFlags int f
901903
if (castSession == null) {
902904
return;
903905
}
904-
volume = VOLUME_RANGE.clamp(volume);
906+
volume = RANGE_DEVICE_VOLUME.clamp(volume);
905907
try {
906908
// See [Internal ref: b/399691860] for context on why we don't use
907909
// RemoteMediaClient.setStreamVolume.
@@ -1103,7 +1105,8 @@ private void updatePlaybackRateAndNotifyIfChanged(@Nullable ResultCallback<?> re
11031105
@RequiresNonNull("castSession")
11041106
private void updateDeviceVolumeAndNotifyIfChanged() {
11051107
if (castSession != null) {
1106-
int deviceVolume = VOLUME_RANGE.clamp((int) Math.round(castSession.getVolume() * MAX_VOLUME));
1108+
int deviceVolume =
1109+
RANGE_DEVICE_VOLUME.clamp((int) Math.round(castSession.getVolume() * MAX_VOLUME));
11071110
setDeviceVolumeAndNotifyIfChanged(deviceVolume, castSession.isMute());
11081111
}
11091112
}

libraries/cast/src/test/java/androidx/media3/cast/CastPlayerTest.java

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package androidx.media3.cast;
1717

1818
import static androidx.media3.common.Player.COMMAND_ADJUST_DEVICE_VOLUME;
19+
import static androidx.media3.common.Player.COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS;
1920
import static androidx.media3.common.Player.COMMAND_CHANGE_MEDIA_ITEMS;
2021
import static androidx.media3.common.Player.COMMAND_GET_AUDIO_ATTRIBUTES;
2122
import static androidx.media3.common.Player.COMMAND_GET_CURRENT_MEDIA_ITEM;
@@ -37,6 +38,7 @@
3738
import static androidx.media3.common.Player.COMMAND_SEEK_TO_PREVIOUS;
3839
import static androidx.media3.common.Player.COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM;
3940
import static androidx.media3.common.Player.COMMAND_SET_DEVICE_VOLUME;
41+
import static androidx.media3.common.Player.COMMAND_SET_DEVICE_VOLUME_WITH_FLAGS;
4042
import static androidx.media3.common.Player.COMMAND_SET_MEDIA_ITEM;
4143
import static androidx.media3.common.Player.COMMAND_SET_PLAYLIST_METADATA;
4244
import static androidx.media3.common.Player.COMMAND_SET_REPEAT_MODE;
@@ -1480,36 +1482,14 @@ public void isCommandAvailable_setVolumeIsSupported() {
14801482
castPlayer.addMediaItems(mediaItems);
14811483
updateTimeLine(mediaItems, mediaQueueItemIds, /* currentItemId= */ 1);
14821484

1483-
assertThat(castPlayer.isCommandAvailable(COMMAND_PLAY_PAUSE)).isTrue();
1484-
assertThat(castPlayer.isCommandAvailable(COMMAND_PREPARE)).isTrue();
1485-
assertThat(castPlayer.isCommandAvailable(COMMAND_STOP)).isTrue();
1486-
assertThat(castPlayer.isCommandAvailable(COMMAND_SEEK_TO_DEFAULT_POSITION)).isTrue();
1487-
assertThat(castPlayer.isCommandAvailable(COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM)).isTrue();
1488-
assertThat(castPlayer.isCommandAvailable(COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM)).isFalse();
1489-
assertThat(castPlayer.isCommandAvailable(COMMAND_SEEK_TO_PREVIOUS)).isTrue();
1490-
assertThat(castPlayer.isCommandAvailable(COMMAND_SEEK_TO_NEXT_MEDIA_ITEM)).isTrue();
1491-
assertThat(castPlayer.isCommandAvailable(COMMAND_SEEK_TO_NEXT)).isTrue();
1492-
assertThat(castPlayer.isCommandAvailable(COMMAND_SEEK_TO_MEDIA_ITEM)).isTrue();
1493-
assertThat(castPlayer.isCommandAvailable(COMMAND_SEEK_BACK)).isTrue();
1494-
assertThat(castPlayer.isCommandAvailable(COMMAND_SEEK_FORWARD)).isTrue();
1495-
assertThat(castPlayer.isCommandAvailable(COMMAND_SET_SPEED_AND_PITCH)).isTrue();
1496-
assertThat(castPlayer.isCommandAvailable(COMMAND_SET_SHUFFLE_MODE)).isFalse();
1497-
assertThat(castPlayer.isCommandAvailable(COMMAND_SET_REPEAT_MODE)).isTrue();
1498-
assertThat(castPlayer.isCommandAvailable(COMMAND_GET_CURRENT_MEDIA_ITEM)).isTrue();
1499-
assertThat(castPlayer.isCommandAvailable(COMMAND_GET_TIMELINE)).isTrue();
1500-
assertThat(castPlayer.isCommandAvailable(COMMAND_GET_METADATA)).isTrue();
1501-
assertThat(castPlayer.isCommandAvailable(COMMAND_SET_PLAYLIST_METADATA)).isTrue();
1502-
assertThat(castPlayer.isCommandAvailable(COMMAND_CHANGE_MEDIA_ITEMS)).isTrue();
1503-
assertThat(castPlayer.isCommandAvailable(COMMAND_SET_MEDIA_ITEM)).isTrue();
15041485
assertThat(castPlayer.isCommandAvailable(COMMAND_GET_AUDIO_ATTRIBUTES)).isFalse();
15051486
assertThat(castPlayer.isCommandAvailable(COMMAND_GET_VOLUME)).isTrue();
15061487
assertThat(castPlayer.isCommandAvailable(COMMAND_GET_DEVICE_VOLUME)).isTrue();
15071488
assertThat(castPlayer.isCommandAvailable(COMMAND_SET_VOLUME)).isTrue();
15081489
assertThat(castPlayer.isCommandAvailable(COMMAND_SET_DEVICE_VOLUME)).isTrue();
1490+
assertThat(castPlayer.isCommandAvailable(COMMAND_SET_DEVICE_VOLUME_WITH_FLAGS)).isTrue();
15091491
assertThat(castPlayer.isCommandAvailable(COMMAND_ADJUST_DEVICE_VOLUME)).isTrue();
1510-
assertThat(castPlayer.isCommandAvailable(COMMAND_SET_VIDEO_SURFACE)).isFalse();
1511-
assertThat(castPlayer.isCommandAvailable(COMMAND_GET_TEXT)).isFalse();
1512-
assertThat(castPlayer.isCommandAvailable(COMMAND_RELEASE)).isTrue();
1492+
assertThat(castPlayer.isCommandAvailable(COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS)).isTrue();
15131493
}
15141494

15151495
@Test

0 commit comments

Comments
 (0)