Search in sources :

Example 76 with MediaItem

use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.

the class TransformerEndToEndTest method getProgress_knownDuration_givesIncreasingPercentages.

@Test
public void getProgress_knownDuration_givesIncreasingPercentages() throws Exception {
    Transformer transformer = createTransformerBuilder().build();
    MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_VIDEO_ONLY);
    List<Integer> progresses = new ArrayList<>();
    Handler progressHandler = new Handler(Looper.myLooper()) {

        @Override
        public void handleMessage(Message msg) {
            @Transformer.ProgressState int progressState = transformer.getProgress(progressHolder);
            if (progressState == PROGRESS_STATE_NO_TRANSFORMATION) {
                return;
            }
            if (progressState != PROGRESS_STATE_WAITING_FOR_AVAILABILITY && (progresses.isEmpty() || Iterables.getLast(progresses) != progressHolder.progress)) {
                progresses.add(progressHolder.progress);
            }
            sendEmptyMessage(0);
        }
    };
    transformer.startTransformation(mediaItem, outputPath);
    progressHandler.sendEmptyMessage(0);
    TransformerTestRunner.runUntilCompleted(transformer);
    assertThat(progresses).isInOrder();
    if (!progresses.isEmpty()) {
        // The progress list could be empty if the transformation ends before any progress can be
        // retrieved.
        assertThat(progresses.get(0)).isAtLeast(0);
        assertThat(Iterables.getLast(progresses)).isLessThan(100);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Message(android.os.Message) MediaItem(com.google.android.exoplayer2.MediaItem) ArrayList(java.util.ArrayList) Handler(android.os.Handler) Test(org.junit.Test)

Example 77 with MediaItem

use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.

the class TransformerEndToEndTest method startTransformation_afterBuildUponWithListenerRemoved_onlyCallsRemainingListeners.

@Test
public void startTransformation_afterBuildUponWithListenerRemoved_onlyCallsRemainingListeners() throws Exception {
    Transformer.Listener mockListener1 = mock(Transformer.Listener.class);
    Transformer.Listener mockListener2 = mock(Transformer.Listener.class);
    Transformer.Listener mockListener3 = mock(Transformer.Listener.class);
    Transformer transformer1 = createTransformerBuilder().addListener(mockListener1).addListener(mockListener2).addListener(mockListener3).build();
    Transformer transformer2 = transformer1.buildUpon().removeListener(mockListener2).build();
    MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_AUDIO_VIDEO);
    transformer2.startTransformation(mediaItem, outputPath);
    TransformerTestRunner.runUntilCompleted(transformer2);
    verify(mockListener1, times(1)).onTransformationCompleted(mediaItem);
    verify(mockListener2, never()).onTransformationCompleted(mediaItem);
    verify(mockListener3, times(1)).onTransformationCompleted(mediaItem);
}
Also used : MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 78 with MediaItem

use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.

the class TransformerEndToEndTest method getProgress_noCurrentTransformation_returnsNoTransformation.

@Test
public void getProgress_noCurrentTransformation_returnsNoTransformation() throws Exception {
    Transformer transformer = createTransformerBuilder().build();
    MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_VIDEO_ONLY);
    @Transformer.ProgressState int stateBeforeTransform = transformer.getProgress(progressHolder);
    transformer.startTransformation(mediaItem, outputPath);
    TransformerTestRunner.runUntilCompleted(transformer);
    @Transformer.ProgressState int stateAfterTransform = transformer.getProgress(progressHolder);
    assertThat(stateBeforeTransform).isEqualTo(Transformer.PROGRESS_STATE_NO_TRANSFORMATION);
    assertThat(stateAfterTransform).isEqualTo(Transformer.PROGRESS_STATE_NO_TRANSFORMATION);
}
Also used : MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 79 with MediaItem

use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.

the class TransformerEndToEndTest method startTransformation_withSubtitles_completesSuccessfully.

@Test
public void startTransformation_withSubtitles_completesSuccessfully() throws Exception {
    Transformer transformer = createTransformerBuilder().setTransformationRequest(new TransformationRequest.Builder().setAudioMimeType(MimeTypes.AUDIO_AAC).build()).build();
    MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_WITH_SUBTITLES);
    transformer.startTransformation(mediaItem, outputPath);
    TransformerTestRunner.runUntilCompleted(transformer);
    DumpFileAsserts.assertOutput(context, testMuxer, getDumpFileName(FILE_WITH_SUBTITLES));
}
Also used : MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 80 with MediaItem

use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.

the class TransformerEndToEndTest method startTransformation_withMultipleListeners_callsEachOnFallback.

@Test
public void startTransformation_withMultipleListeners_callsEachOnFallback() throws Exception {
    Transformer.Listener mockListener1 = mock(Transformer.Listener.class);
    Transformer.Listener mockListener2 = mock(Transformer.Listener.class);
    Transformer.Listener mockListener3 = mock(Transformer.Listener.class);
    TransformationRequest originalTransformationRequest = new TransformationRequest.Builder().build();
    TransformationRequest fallbackTransformationRequest = new TransformationRequest.Builder().setAudioMimeType(MimeTypes.AUDIO_AAC).build();
    Transformer transformer = createTransformerBuilder().addListener(mockListener1).addListener(mockListener2).addListener(mockListener3).build();
    MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_AUDIO_UNSUPPORTED_BY_MUXER);
    transformer.startTransformation(mediaItem, outputPath);
    TransformerTestRunner.runUntilCompleted(transformer);
    verify(mockListener1, times(1)).onFallbackApplied(mediaItem, originalTransformationRequest, fallbackTransformationRequest);
    verify(mockListener2, times(1)).onFallbackApplied(mediaItem, originalTransformationRequest, fallbackTransformationRequest);
    verify(mockListener3, times(1)).onFallbackApplied(mediaItem, originalTransformationRequest, fallbackTransformationRequest);
}
Also used : MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Aggregations

MediaItem (com.google.android.exoplayer2.MediaItem)160 Test (org.junit.Test)151 MediaSource (com.google.android.exoplayer2.source.MediaSource)31 ArrayList (java.util.ArrayList)29 Timeline (com.google.android.exoplayer2.Timeline)25 InOrder (org.mockito.InOrder)20 Nullable (androidx.annotation.Nullable)19 AdsMediaSource (com.google.android.exoplayer2.source.ads.AdsMediaSource)19 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)19 Player (com.google.android.exoplayer2.Player)17 Uri (android.net.Uri)15 Listener (com.google.android.exoplayer2.Player.Listener)15 TestPlayerRunHelper.playUntilStartOfMediaItem (com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.playUntilStartOfMediaItem)15 DefaultMediaSourceFactory (com.google.android.exoplayer2.source.DefaultMediaSourceFactory)15 AnalyticsListener (com.google.android.exoplayer2.analytics.AnalyticsListener)13 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)13 TransferListener (com.google.android.exoplayer2.upstream.TransferListener)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)12 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)12