Search in sources :

Example 21 with Clock

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

the class RobolectricUtilTest method runMainLooperUntil_withConditionThatNeverBecomesTrue_timesOut.

@Test
public void runMainLooperUntil_withConditionThatNeverBecomesTrue_timesOut() {
    Clock mockClock = mock(Clock.class);
    when(mockClock.currentTimeMillis()).thenReturn(0L, 41L, 42L);
    assertThrows(TimeoutException.class, () -> RobolectricUtil.runMainLooperUntil(() -> false, /* timeoutMs= */
    42, mockClock));
    verify(mockClock, times(3)).currentTimeMillis();
}
Also used : Clock(androidx.media3.common.util.Clock) Test(org.junit.Test)

Example 22 with Clock

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

the class Transformer method startTransformation.

private void startTransformation(MediaItem mediaItem, Muxer muxer) {
    verifyApplicationThread();
    if (player != null) {
        throw new IllegalStateException("There is already a transformation in progress.");
    }
    MuxerWrapper muxerWrapper = new MuxerWrapper(muxer, muxerFactory, containerMimeType);
    this.muxerWrapper = muxerWrapper;
    DefaultTrackSelector trackSelector = new DefaultTrackSelector(context);
    trackSelector.setParameters(new DefaultTrackSelector.ParametersBuilder(context).setForceHighestSupportedBitrate(true).build());
    // Arbitrarily decrease buffers for playback so that samples start being sent earlier to the
    // muxer (rebuffers are less problematic for the transformation use case).
    DefaultLoadControl loadControl = new DefaultLoadControl.Builder().setBufferDurationsMs(DEFAULT_MIN_BUFFER_MS, DEFAULT_MAX_BUFFER_MS, DEFAULT_BUFFER_FOR_PLAYBACK_MS / 10, DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS / 10).build();
    ExoPlayer.Builder playerBuilder = new ExoPlayer.Builder(context, new TransformerRenderersFactory(context, muxerWrapper, removeAudio, removeVideo, transformationRequest, encoderFactory, decoderFactory, new FallbackListener(mediaItem, listeners, transformationRequest), debugViewProvider)).setMediaSourceFactory(mediaSourceFactory).setTrackSelector(trackSelector).setLoadControl(loadControl).setLooper(looper);
    if (clock != Clock.DEFAULT) {
        // Transformer.Builder#setClock is also @VisibleForTesting, so if we're using a non-default
        // clock we must be in a test context.
        @SuppressWarnings("VisibleForTests") ExoPlayer.Builder unusedForAnnotation = playerBuilder.setClock(clock);
    }
    player = playerBuilder.build();
    player.setMediaItem(mediaItem);
    player.addListener(new TransformerPlayerListener(mediaItem, muxerWrapper));
    player.prepare();
    progressState = PROGRESS_STATE_WAITING_FOR_AVAILABILITY;
}
Also used : DefaultTrackSelector(androidx.media3.exoplayer.trackselection.DefaultTrackSelector) ExoPlayer(androidx.media3.exoplayer.ExoPlayer) DefaultLoadControl(androidx.media3.exoplayer.DefaultLoadControl)

Example 23 with Clock

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

the class MetadataRetriever method retrieveMetadata.

@VisibleForTesting
static /* package */
ListenableFuture<TrackGroupArray> retrieveMetadata(Context context, MediaItem mediaItem, Clock clock) {
    ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory().setMp4ExtractorFlags(Mp4Extractor.FLAG_READ_MOTION_PHOTO_METADATA | Mp4Extractor.FLAG_READ_SEF_DATA);
    MediaSource.Factory mediaSourceFactory = new DefaultMediaSourceFactory(context, extractorsFactory);
    return retrieveMetadata(mediaSourceFactory, mediaItem, clock);
}
Also used : DefaultExtractorsFactory(androidx.media3.extractor.DefaultExtractorsFactory) MediaSource(androidx.media3.exoplayer.source.MediaSource) DefaultExtractorsFactory(androidx.media3.extractor.DefaultExtractorsFactory) ExtractorsFactory(androidx.media3.extractor.ExtractorsFactory) DefaultMediaSourceFactory(androidx.media3.exoplayer.source.DefaultMediaSourceFactory) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 24 with Clock

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

the class RtspPlaybackTest method prepare_noSupportedTrack_throwsPreparationError.

@Test
public void prepare_noSupportedTrack_throwsPreparationError() throws Exception {
    try (RtspServer rtspServer = new RtspServer(new ResponseProvider(clock, ImmutableList.of(mp4aLatmRtpPacketStreamDump), fakeRtpDataChannel))) {
        ExoPlayer player = createExoPlayer(rtspServer.startAndGetPortNumber(), rtpDataChannelFactory);
        AtomicReference<Throwable> playbackError = new AtomicReference<>();
        player.prepare();
        player.addListener(new Listener() {

            @Override
            public void onPlayerError(PlaybackException error) {
                playbackError.set(error);
            }
        });
        RobolectricUtil.runMainLooperUntil(() -> playbackError.get() != null);
        player.release();
        assertThat(playbackError.get()).hasCauseThat().hasMessageThat().contains("No playable track.");
    }
}
Also used : PlaybackException(androidx.media3.common.PlaybackException) Listener(androidx.media3.common.Player.Listener) AtomicReference(java.util.concurrent.atomic.AtomicReference) ExoPlayer(androidx.media3.exoplayer.ExoPlayer) Test(org.junit.Test)

Example 25 with Clock

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

the class RtspPlaybackTest method prepare_withSupportedTrack_playsTrackUntilEnded.

@Test
public void prepare_withSupportedTrack_playsTrackUntilEnded() throws Exception {
    ResponseProvider responseProvider = new ResponseProvider(clock, ImmutableList.of(aacRtpPacketStreamDump, mp4aLatmRtpPacketStreamDump), fakeRtpDataChannel);
    try (RtspServer rtspServer = new RtspServer(responseProvider)) {
        ExoPlayer player = createExoPlayer(rtspServer.startAndGetPortNumber(), rtpDataChannelFactory);
        PlaybackOutput playbackOutput = PlaybackOutput.register(player, capturingRenderersFactory);
        player.prepare();
        player.play();
        TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_ENDED);
        player.release();
        // Only setup the supported track (aac).
        assertThat(responseProvider.getDumpsForSetUpTracks()).containsExactly(aacRtpPacketStreamDump);
        DumpFileAsserts.assertOutput(applicationContext, playbackOutput, "playbackdumps/rtsp/aac.dump");
    }
}
Also used : PlaybackOutput(androidx.media3.test.utils.robolectric.PlaybackOutput) ExoPlayer(androidx.media3.exoplayer.ExoPlayer) 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