use of androidx.media3.session.RemoteMediaSession.RemoteMockPlayer in project media by androidx.
the class MediaControllerListenerTest method onPositionDiscontinuity_updatesGetters.
@Test
public void onPositionDiscontinuity_updatesGetters() throws Exception {
long testCurrentPositionMs = 11;
long testContentPositionMs = 33;
long testDurationMs = 200;
long testBufferedPositionMs = 100;
int testBufferedPercentage = 50;
long testTotalBufferedDurationMs = 120;
long testCurrentLiveOffsetMs = 10;
long testContentDurationMs = 300;
long testContentBufferedPositionMs = 240;
boolean testIsPlayingAd = true;
int testCurrentAdGroupIndex = 33;
int testCurrentAdIndexInAdGroup = 11;
PositionInfo newPositionInfo = new PositionInfo(/* windowUid= */
null, /* mediaItemIndex= */
C.INDEX_UNSET, /* mediaItem= */
null, /* periodUid= */
null, /* periodIndex= */
C.INDEX_UNSET, testCurrentPositionMs, testContentPositionMs, testCurrentAdGroupIndex, testCurrentAdIndexInAdGroup);
MediaController controller = controllerTestRule.createController(remoteSession.getToken());
CountDownLatch latch = new CountDownLatch(1);
AtomicLong currentPositionMsRef = new AtomicLong();
AtomicLong contentPositionMsRef = new AtomicLong();
AtomicLong durationMsRef = new AtomicLong();
AtomicLong bufferedPositionMsRef = new AtomicLong();
AtomicInteger bufferedPercentageRef = new AtomicInteger();
AtomicLong totalBufferedDurationMsRef = new AtomicLong();
AtomicLong currentLiveOffsetMsRef = new AtomicLong();
AtomicLong contentDurationMsRef = new AtomicLong();
AtomicLong contentBufferedPositionMsRef = new AtomicLong();
AtomicBoolean isPlayingAdRef = new AtomicBoolean();
AtomicInteger currentAdGroupIndexRef = new AtomicInteger();
AtomicInteger currentAdIndexInAdGroupRef = new AtomicInteger();
Player.Listener listener = new Player.Listener() {
@Override
public void onPositionDiscontinuity(PositionInfo oldPosition, PositionInfo newPosition, @DiscontinuityReason int reason) {
currentPositionMsRef.set(controller.getCurrentPosition());
contentPositionMsRef.set(controller.getContentPosition());
durationMsRef.set(controller.getDuration());
bufferedPositionMsRef.set(controller.getBufferedPosition());
bufferedPercentageRef.set(controller.getBufferedPercentage());
totalBufferedDurationMsRef.set(controller.getTotalBufferedDuration());
currentLiveOffsetMsRef.set(controller.getCurrentLiveOffset());
contentDurationMsRef.set(controller.getContentDuration());
contentBufferedPositionMsRef.set(controller.getContentBufferedPosition());
isPlayingAdRef.set(controller.isPlayingAd());
currentAdGroupIndexRef.set(controller.getCurrentAdGroupIndex());
currentAdIndexInAdGroupRef.set(controller.getCurrentAdIndexInAdGroup());
latch.countDown();
}
};
threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener));
RemoteMockPlayer remoteMockPlayer = remoteSession.getMockPlayer();
remoteMockPlayer.setCurrentPosition(testCurrentPositionMs);
remoteMockPlayer.setContentPosition(testContentPositionMs);
remoteMockPlayer.setDuration(testDurationMs);
remoteMockPlayer.setBufferedPosition(testBufferedPositionMs);
remoteMockPlayer.setBufferedPercentage(testBufferedPercentage);
remoteMockPlayer.setTotalBufferedDuration(testTotalBufferedDurationMs);
remoteMockPlayer.setCurrentLiveOffset(testCurrentLiveOffsetMs);
remoteMockPlayer.setContentDuration(testContentDurationMs);
remoteMockPlayer.setContentBufferedPosition(testContentBufferedPositionMs);
remoteMockPlayer.setIsPlayingAd(testIsPlayingAd);
remoteMockPlayer.setCurrentAdGroupIndex(testCurrentAdGroupIndex);
remoteMockPlayer.setCurrentAdIndexInAdGroup(testCurrentAdIndexInAdGroup);
remoteMockPlayer.notifyPositionDiscontinuity(/* oldPositionInfo= */
SessionPositionInfo.DEFAULT_POSITION_INFO, newPositionInfo, Player.DISCONTINUITY_REASON_INTERNAL);
assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
assertThat(currentPositionMsRef.get()).isEqualTo(testCurrentPositionMs);
assertThat(contentPositionMsRef.get()).isEqualTo(testContentPositionMs);
assertThat(durationMsRef.get()).isEqualTo(testDurationMs);
assertThat(bufferedPositionMsRef.get()).isEqualTo(testBufferedPositionMs);
assertThat(bufferedPercentageRef.get()).isEqualTo(testBufferedPercentage);
assertThat(totalBufferedDurationMsRef.get()).isEqualTo(testTotalBufferedDurationMs);
assertThat(currentLiveOffsetMsRef.get()).isEqualTo(testCurrentLiveOffsetMs);
assertThat(contentDurationMsRef.get()).isEqualTo(testContentDurationMs);
assertThat(contentBufferedPositionMsRef.get()).isEqualTo(testContentBufferedPositionMs);
assertThat(isPlayingAdRef.get()).isEqualTo(testIsPlayingAd);
assertThat(currentAdGroupIndexRef.get()).isEqualTo(testCurrentAdGroupIndex);
assertThat(currentAdIndexInAdGroupRef.get()).isEqualTo(testCurrentAdIndexInAdGroup);
}
Aggregations