|
42 | 42 | import androidx.media3.common.MediaItem;
|
43 | 43 | import androidx.media3.common.MediaLibraryInfo;
|
44 | 44 | import androidx.media3.common.MediaMetadata;
|
| 45 | +import androidx.media3.common.Metadata; |
45 | 46 | import androidx.media3.common.PlaybackException;
|
46 | 47 | import androidx.media3.common.PlaybackParameters;
|
47 | 48 | import androidx.media3.common.Player;
|
|
50 | 51 | import androidx.media3.common.StarRating;
|
51 | 52 | import androidx.media3.common.Timeline;
|
52 | 53 | import androidx.media3.common.TrackGroup;
|
| 54 | +import androidx.media3.common.TrackSelectionOverride; |
53 | 55 | import androidx.media3.common.TrackSelectionParameters;
|
54 | 56 | import androidx.media3.common.Tracks;
|
55 | 57 | import androidx.media3.common.VideoSize;
|
@@ -427,7 +429,7 @@ public void gettersAfterConnected() throws Exception {
|
427 | 429 | assertThat(seekForwardIncrementRef.get()).isEqualTo(seekForwardIncrementMs);
|
428 | 430 | assertThat(maxSeekToPreviousPositionMsRef.get()).isEqualTo(maxSeekToPreviousPositionMs);
|
429 | 431 | assertThat(trackSelectionParametersRef.get()).isEqualTo(trackSelectionParameters);
|
430 |
| - assertThat(currentTracksRef.get()).isEqualTo(currentTracks); |
| 432 | + assertThat(currentTracksRef.get().getGroups()).hasSize(2); |
431 | 433 | assertTimelineMediaItemsEquals(timelineRef.get(), timeline);
|
432 | 434 | assertThat(currentMediaItemIndexRef.get()).isEqualTo(currentMediaItemIndex);
|
433 | 435 | assertThat(currentMediaItemRef.get()).isEqualTo(currentMediaItem);
|
@@ -1211,6 +1213,118 @@ public void getMediaMetadata() throws Exception {
|
1211 | 1213 | assertThat(mediaMetadata).isEqualTo(testMediaMetadata);
|
1212 | 1214 | }
|
1213 | 1215 |
|
| 1216 | + @Test |
| 1217 | + public void getCurrentTracks_hasEqualTrackGroupsForEqualGroupsInPlayer() throws Exception { |
| 1218 | + // Include metadata in Format to ensure the track group can't be fully bundled. |
| 1219 | + Tracks initialPlayerTracks = |
| 1220 | + new Tracks( |
| 1221 | + ImmutableList.of( |
| 1222 | + new Tracks.Group( |
| 1223 | + new TrackGroup( |
| 1224 | + new Format.Builder().setMetadata(new Metadata()).setId("1").build()), |
| 1225 | + /* adaptiveSupported= */ false, |
| 1226 | + /* trackSupport= */ new int[1], |
| 1227 | + /* trackSelected= */ new boolean[1]), |
| 1228 | + new Tracks.Group( |
| 1229 | + new TrackGroup( |
| 1230 | + new Format.Builder().setMetadata(new Metadata()).setId("2").build()), |
| 1231 | + /* adaptiveSupported= */ false, |
| 1232 | + /* trackSupport= */ new int[1], |
| 1233 | + /* trackSelected= */ new boolean[1]))); |
| 1234 | + Tracks updatedPlayerTracks = |
| 1235 | + new Tracks( |
| 1236 | + ImmutableList.of( |
| 1237 | + new Tracks.Group( |
| 1238 | + new TrackGroup( |
| 1239 | + new Format.Builder().setMetadata(new Metadata()).setId("2").build()), |
| 1240 | + /* adaptiveSupported= */ true, |
| 1241 | + /* trackSupport= */ new int[] {C.FORMAT_HANDLED}, |
| 1242 | + /* trackSelected= */ new boolean[] {true}), |
| 1243 | + new Tracks.Group( |
| 1244 | + new TrackGroup( |
| 1245 | + new Format.Builder().setMetadata(new Metadata()).setId("3").build()), |
| 1246 | + /* adaptiveSupported= */ false, |
| 1247 | + /* trackSupport= */ new int[1], |
| 1248 | + /* trackSelected= */ new boolean[1]))); |
| 1249 | + Bundle playerConfig = |
| 1250 | + new RemoteMediaSession.MockPlayerConfigBuilder() |
| 1251 | + .setCurrentTracks(initialPlayerTracks) |
| 1252 | + .build(); |
| 1253 | + remoteSession.setPlayer(playerConfig); |
| 1254 | + MediaController controller = controllerTestRule.createController(remoteSession.getToken()); |
| 1255 | + CountDownLatch trackChangedEvent = new CountDownLatch(1); |
| 1256 | + threadTestRule |
| 1257 | + .getHandler() |
| 1258 | + .postAndSync( |
| 1259 | + () -> |
| 1260 | + controller.addListener( |
| 1261 | + new Player.Listener() { |
| 1262 | + @Override |
| 1263 | + public void onTracksChanged(Tracks tracks) { |
| 1264 | + trackChangedEvent.countDown(); |
| 1265 | + } |
| 1266 | + })); |
| 1267 | + |
| 1268 | + Tracks initialControllerTracks = |
| 1269 | + threadTestRule.getHandler().postAndSync(controller::getCurrentTracks); |
| 1270 | + // Do something unrelated first to ensure tracks are correctly kept even after multiple updates. |
| 1271 | + remoteSession.getMockPlayer().notifyPlaybackStateChanged(Player.STATE_READY); |
| 1272 | + remoteSession.getMockPlayer().notifyTracksChanged(updatedPlayerTracks); |
| 1273 | + trackChangedEvent.await(); |
| 1274 | + Tracks updatedControllerTracks = |
| 1275 | + threadTestRule.getHandler().postAndSync(controller::getCurrentTracks); |
| 1276 | + |
| 1277 | + assertThat(initialControllerTracks.getGroups()).hasSize(2); |
| 1278 | + assertThat(updatedControllerTracks.getGroups()).hasSize(2); |
| 1279 | + assertThat(initialControllerTracks.getGroups().get(1).getMediaTrackGroup()) |
| 1280 | + .isEqualTo(updatedControllerTracks.getGroups().get(0).getMediaTrackGroup()); |
| 1281 | + } |
| 1282 | + |
| 1283 | + @Test |
| 1284 | + public void getCurrentTracksAndTrackOverrides_haveEqualTrackGroupsForEqualGroupsInPlayer() |
| 1285 | + throws Exception { |
| 1286 | + // Include metadata in Format to ensure the track group can't be fully bundled. |
| 1287 | + TrackGroup playerTrackGroupForOverride = |
| 1288 | + new TrackGroup(new Format.Builder().setMetadata(new Metadata()).setId("2").build()); |
| 1289 | + Tracks playerTracks = |
| 1290 | + new Tracks( |
| 1291 | + ImmutableList.of( |
| 1292 | + new Tracks.Group( |
| 1293 | + new TrackGroup( |
| 1294 | + new Format.Builder().setMetadata(new Metadata()).setId("1").build()), |
| 1295 | + /* adaptiveSupported= */ false, |
| 1296 | + /* trackSupport= */ new int[1], |
| 1297 | + /* trackSelected= */ new boolean[1]), |
| 1298 | + new Tracks.Group( |
| 1299 | + playerTrackGroupForOverride, |
| 1300 | + /* adaptiveSupported= */ false, |
| 1301 | + /* trackSupport= */ new int[1], |
| 1302 | + /* trackSelected= */ new boolean[1]))); |
| 1303 | + TrackSelectionParameters trackSelectionParameters = |
| 1304 | + TrackSelectionParameters.DEFAULT_WITHOUT_CONTEXT |
| 1305 | + .buildUpon() |
| 1306 | + .addOverride( |
| 1307 | + new TrackSelectionOverride(playerTrackGroupForOverride, /* trackIndex= */ 0)) |
| 1308 | + .build(); |
| 1309 | + Bundle playerConfig = |
| 1310 | + new RemoteMediaSession.MockPlayerConfigBuilder() |
| 1311 | + .setCurrentTracks(playerTracks) |
| 1312 | + .setTrackSelectionParameters(trackSelectionParameters) |
| 1313 | + .build(); |
| 1314 | + remoteSession.setPlayer(playerConfig); |
| 1315 | + MediaController controller = controllerTestRule.createController(remoteSession.getToken()); |
| 1316 | + |
| 1317 | + Tracks controllerTracks = threadTestRule.getHandler().postAndSync(controller::getCurrentTracks); |
| 1318 | + TrackSelectionParameters controllerTrackSelectionParameters = |
| 1319 | + threadTestRule.getHandler().postAndSync(controller::getTrackSelectionParameters); |
| 1320 | + |
| 1321 | + TrackGroup controllerTrackGroup = controllerTracks.getGroups().get(1).getMediaTrackGroup(); |
| 1322 | + assertThat(controllerTrackSelectionParameters.overrides) |
| 1323 | + .containsExactly( |
| 1324 | + controllerTrackGroup, |
| 1325 | + new TrackSelectionOverride(controllerTrackGroup, /* trackIndex= */ 0)); |
| 1326 | + } |
| 1327 | + |
1214 | 1328 | @Test
|
1215 | 1329 | public void
|
1216 | 1330 | setMediaItems_setLessMediaItemsThanCurrentMediaItemIndex_masksCurrentMediaItemIndexAndStateCorrectly()
|
|
0 commit comments