Skip to content

Commit

Permalink
Add test case to test position conversion when POSITION_UNKNOWN
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 584261559
  • Loading branch information
marcbaechinger authored and copybara-github committed Nov 21, 2023
1 parent 167f50a commit ec47813
Showing 1 changed file with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.media.AudioManager;
import android.os.Bundle;
import android.os.RemoteException;
import android.support.v4.media.session.MediaControllerCompat;
import android.support.v4.media.session.MediaSessionCompat;
import android.support.v4.media.session.PlaybackStateCompat;
import androidx.media.VolumeProviderCompat;
Expand Down Expand Up @@ -232,7 +233,7 @@ public void onEvents(Player player, Player.Events events) {
session.setQueueTitle("queue-title");

assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
assertThat(playlistMetadataParamRef.get().title).isEqualTo("queue-title");
assertThat(playlistMetadataParamRef.get().title.toString()).isEqualTo("queue-title");
assertThat(playlistMetadataGetterRef.get()).isEqualTo(playlistMetadataParamRef.get());
assertThat(playlistMetadataOnEventsRef.get()).isEqualTo(playlistMetadataParamRef.get());
assertThat(getEventsAsList(onEvents.get()))
Expand All @@ -250,7 +251,7 @@ public void onAudioAttributesChanged() throws Exception {
/* volumeControl= */ VolumeProviderCompat.VOLUME_CONTROL_ABSOLUTE,
/* maxVolume= */ 100,
/* currentVolume= */ 50,
/* routingSessionId= */ "route");
/* routingControllerId= */ "route");
MediaController controller = controllerTestRule.createController(session.getSessionToken());
CountDownLatch latch = new CountDownLatch(2);
AtomicReference<AudioAttributes> audioAttributesParamRef = new AtomicReference<>();
Expand Down Expand Up @@ -356,7 +357,7 @@ public void onEvents(Player player, Player.Events events) {
/* volumeControl= */ VolumeProviderCompat.VOLUME_CONTROL_ABSOLUTE,
/* maxVolume= */ 100,
/* currentVolume= */ 50,
/* routingSessionId= */ "route");
/* routingControllerId= */ "route");

assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
assertThat(deviceVolumeParam.get()).isEqualTo(50);
Expand Down Expand Up @@ -447,4 +448,24 @@ public void onCustomLayoutChanged(
.containsExactly(expectedFirstCustomLayout, expectedSecondCustomLayout)
.inOrder();
}

@Test
public void getCurrentPosition_unknownPlaybackPosition_convertedToZero() throws Exception {
session.setPlaybackState(
new PlaybackStateCompat.Builder()
.setState(
PlaybackStateCompat.STATE_NONE,
PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN,
/* playbackSpeed= */ 1.0f)
.build());
MediaControllerCompat legacyController =
new MediaControllerCompat(
ApplicationProvider.getApplicationContext(), session.getSessionToken());
MediaController controller = controllerTestRule.createController(session.getSessionToken());

assertThat(legacyController.getPlaybackState().getPosition())
.isEqualTo(PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN);
assertThat(threadTestRule.getHandler().postAndSync(controller::getCurrentPosition))
.isEqualTo(0);
}
}

0 comments on commit ec47813

Please sign in to comment.