Search in sources :

Example 16 with Clock

use of androidx.media3.common.util.Clock in project media by androidx.

the class DefaultBandwidthMeterTest method networkTypeOverride_doesFullReset.

@Test
public void networkTypeOverride_doesFullReset() {
    // Simulate transfers for an ethernet connection.
    setActiveNetworkInfo(networkInfoEthernet);
    FakeClock clock = new FakeClock(/* initialTimeMs= */
    0);
    DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).setClock(clock).build();
    long[] bitrateEstimatesWithNewInstance = simulateTransfers(bandwidthMeter, clock);
    // Create a new instance and seed with some transfers.
    setActiveNetworkInfo(networkInfo2g);
    bandwidthMeter = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).setClock(clock).build();
    simulateTransfers(bandwidthMeter, clock);
    // Override the network type to ethernet and simulate transfers again.
    bandwidthMeter.setNetworkTypeOverride(C.NETWORK_TYPE_ETHERNET);
    long[] bitrateEstimatesAfterReset = simulateTransfers(bandwidthMeter, clock);
    // If overriding the network type fully reset the bandwidth meter, we expect the bitrate
    // estimates generated during simulation to be the same.
    assertThat(bitrateEstimatesAfterReset).isEqualTo(bitrateEstimatesWithNewInstance);
}
Also used : FakeClock(androidx.media3.test.utils.FakeClock) Test(org.junit.Test)

Example 17 with Clock

use of androidx.media3.common.util.Clock in project media by androidx.

the class MetadataRetrieverTest method retrieveMetadata_heicMotionPhoto_outputsExpectedMetadata.

@Test
public void retrieveMetadata_heicMotionPhoto_outputsExpectedMetadata() throws Exception {
    MediaItem mediaItem = MediaItem.fromUri(Uri.parse("asset://android_asset/media/mp4/sample_MP.heic"));
    MotionPhotoMetadata expectedMotionPhotoMetadata = new MotionPhotoMetadata(/* photoStartPosition= */
    0, /* photoSize= */
    28_853, /* photoPresentationTimestampUs= */
    C.TIME_UNSET, /* videoStartPosition= */
    28_869, /* videoSize= */
    28_803);
    ListenableFuture<TrackGroupArray> trackGroupsFuture = retrieveMetadata(context, mediaItem, clock);
    ShadowLooper.idleMainLooper();
    TrackGroupArray trackGroups = trackGroupsFuture.get(TEST_TIMEOUT_SEC, TimeUnit.SECONDS);
    assertThat(trackGroups.length).isEqualTo(1);
    assertThat(trackGroups.get(0).length).isEqualTo(1);
    assertThat(trackGroups.get(0).getFormat(0).metadata.length()).isEqualTo(1);
    assertThat(trackGroups.get(0).getFormat(0).metadata.get(0)).isEqualTo(expectedMotionPhotoMetadata);
}
Also used : MotionPhotoMetadata(androidx.media3.extractor.metadata.mp4.MotionPhotoMetadata) MediaItem(androidx.media3.common.MediaItem) TrackGroupArray(androidx.media3.common.TrackGroupArray) Test(org.junit.Test)

Example 18 with Clock

use of androidx.media3.common.util.Clock in project media by androidx.

the class MetadataRetrieverTest method retrieveMetadata_singleMediaItem_outputsExpectedMetadata.

@Test
public void retrieveMetadata_singleMediaItem_outputsExpectedMetadata() throws Exception {
    MediaItem mediaItem = MediaItem.fromUri(Uri.parse("asset://android_asset/media/mp4/sample.mp4"));
    ListenableFuture<TrackGroupArray> trackGroupsFuture = retrieveMetadata(context, mediaItem, clock);
    ShadowLooper.idleMainLooper();
    TrackGroupArray trackGroups = trackGroupsFuture.get(TEST_TIMEOUT_SEC, TimeUnit.SECONDS);
    assertThat(trackGroups.length).isEqualTo(2);
    // Video group.
    assertThat(trackGroups.get(0).length).isEqualTo(1);
    assertThat(trackGroups.get(0).getFormat(0).sampleMimeType).isEqualTo(MimeTypes.VIDEO_H264);
    // Audio group.
    assertThat(trackGroups.get(1).length).isEqualTo(1);
    assertThat(trackGroups.get(1).getFormat(0).sampleMimeType).isEqualTo(MimeTypes.AUDIO_AAC);
}
Also used : MediaItem(androidx.media3.common.MediaItem) TrackGroupArray(androidx.media3.common.TrackGroupArray) Test(org.junit.Test)

Example 19 with Clock

use of androidx.media3.common.util.Clock in project media by androidx.

the class MetadataRetrieverTest method retrieveMetadata_multipleMediaItems_outputsExpectedMetadata.

@Test
public void retrieveMetadata_multipleMediaItems_outputsExpectedMetadata() throws Exception {
    MediaItem mediaItem1 = MediaItem.fromUri(Uri.parse("asset://android_asset/media/mp4/sample.mp4"));
    MediaItem mediaItem2 = MediaItem.fromUri(Uri.parse("asset://android_asset/media/mp3/bear-id3.mp3"));
    ListenableFuture<TrackGroupArray> trackGroupsFuture1 = retrieveMetadata(context, mediaItem1, clock);
    ListenableFuture<TrackGroupArray> trackGroupsFuture2 = retrieveMetadata(context, mediaItem2, clock);
    ShadowLooper.idleMainLooper();
    TrackGroupArray trackGroups1 = trackGroupsFuture1.get(TEST_TIMEOUT_SEC, TimeUnit.SECONDS);
    TrackGroupArray trackGroups2 = trackGroupsFuture2.get(TEST_TIMEOUT_SEC, TimeUnit.SECONDS);
    // First track group.
    assertThat(trackGroups1.length).isEqualTo(2);
    // First track group - Video group.
    assertThat(trackGroups1.get(0).length).isEqualTo(1);
    assertThat(trackGroups1.get(0).getFormat(0).sampleMimeType).isEqualTo(MimeTypes.VIDEO_H264);
    // First track group - Audio group.
    assertThat(trackGroups1.get(1).length).isEqualTo(1);
    assertThat(trackGroups1.get(1).getFormat(0).sampleMimeType).isEqualTo(MimeTypes.AUDIO_AAC);
    // Second track group.
    assertThat(trackGroups2.length).isEqualTo(1);
    // Second track group - Audio group.
    assertThat(trackGroups2.get(0).length).isEqualTo(1);
    assertThat(trackGroups2.get(0).getFormat(0).sampleMimeType).isEqualTo(MimeTypes.AUDIO_MPEG);
}
Also used : MediaItem(androidx.media3.common.MediaItem) TrackGroupArray(androidx.media3.common.TrackGroupArray) Test(org.junit.Test)

Example 20 with Clock

use of androidx.media3.common.util.Clock in project media by androidx.

the class MetadataRetrieverTest method retrieveMetadata_invalidMediaItem_throwsError.

@Test
public void retrieveMetadata_invalidMediaItem_throwsError() {
    MediaItem mediaItem = MediaItem.fromUri(Uri.parse("asset://android_asset/media/does_not_exist"));
    ListenableFuture<TrackGroupArray> trackGroupsFuture = retrieveMetadata(context, mediaItem, clock);
    ShadowLooper.idleMainLooper();
    assertThrows(ExecutionException.class, () -> trackGroupsFuture.get(TEST_TIMEOUT_SEC, TimeUnit.SECONDS));
}
Also used : MediaItem(androidx.media3.common.MediaItem) TrackGroupArray(androidx.media3.common.TrackGroupArray) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)17 MediaItem (androidx.media3.common.MediaItem)6 TrackGroupArray (androidx.media3.common.TrackGroupArray)6 ExoPlayer (androidx.media3.exoplayer.ExoPlayer)5 Clock (androidx.media3.common.util.Clock)4 FakeClock (androidx.media3.test.utils.FakeClock)4 FakeMediaClockRenderer (androidx.media3.test.utils.FakeMediaClockRenderer)4 Listener (androidx.media3.common.Player.Listener)3 Before (org.junit.Before)3 PlaybackParameters (androidx.media3.common.PlaybackParameters)2 Player (androidx.media3.common.Player)2 MediaSource (androidx.media3.exoplayer.source.MediaSource)2 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)2 TestExoPlayerBuilder (androidx.media3.test.utils.TestExoPlayerBuilder)2 ArrayList (java.util.ArrayList)2 HandlerThread (android.os.HandlerThread)1 VisibleForTesting (androidx.annotation.VisibleForTesting)1 AdPlaybackState (androidx.media3.common.AdPlaybackState)1 Format (androidx.media3.common.Format)1 PlaybackException (androidx.media3.common.PlaybackException)1