Search in sources :

Example 6 with ProgressHolder

use of com.google.android.exoplayer2.transformer.ProgressHolder in project ExoPlayer by google.

the class TransformerEndToEndTest method getProgress_unknownDuration_returnsConsistentStates.

@Test
public void getProgress_unknownDuration_returnsConsistentStates() throws Exception {
    Transformer transformer = createTransformerBuilder().build();
    MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_UNKNOWN_DURATION);
    AtomicInteger previousProgressState = new AtomicInteger(PROGRESS_STATE_WAITING_FOR_AVAILABILITY);
    AtomicBoolean foundInconsistentState = new AtomicBoolean();
    Handler progressHandler = new Handler(Looper.myLooper()) {

        @Override
        public void handleMessage(Message msg) {
            @Transformer.ProgressState int progressState = transformer.getProgress(progressHolder);
            switch(previousProgressState.get()) {
                case PROGRESS_STATE_WAITING_FOR_AVAILABILITY:
                    break;
                case PROGRESS_STATE_UNAVAILABLE:
                case // See [Internal: b/176145097].
                PROGRESS_STATE_AVAILABLE:
                    if (progressState == PROGRESS_STATE_WAITING_FOR_AVAILABILITY) {
                        foundInconsistentState.set(true);
                        return;
                    }
                    break;
                case PROGRESS_STATE_NO_TRANSFORMATION:
                    if (progressState != PROGRESS_STATE_NO_TRANSFORMATION) {
                        foundInconsistentState.set(true);
                        return;
                    }
                    break;
                default:
                    throw new IllegalStateException();
            }
            previousProgressState.set(progressState);
            sendEmptyMessage(0);
        }
    };
    transformer.startTransformation(mediaItem, outputPath);
    progressHandler.sendEmptyMessage(0);
    TransformerTestRunner.runUntilCompleted(transformer);
    assertThat(foundInconsistentState.get()).isFalse();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Message(android.os.Message) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MediaItem(com.google.android.exoplayer2.MediaItem) Handler(android.os.Handler) Test(org.junit.Test)

Example 7 with ProgressHolder

use of com.google.android.exoplayer2.transformer.ProgressHolder in project ExoPlayer by google.

the class TransformerEndToEndTest method setUp.

@Before
public void setUp() throws Exception {
    context = ApplicationProvider.getApplicationContext();
    outputPath = Util.createTempFile(context, "TransformerTest").getPath();
    clock = new FakeClock(/* isAutoAdvancing= */
    true);
    progressHolder = new ProgressHolder();
    createEncodersAndDecoders();
}
Also used : FakeClock(com.google.android.exoplayer2.testutil.FakeClock) Before(org.junit.Before)

Aggregations

Handler (android.os.Handler)4 MediaItem (com.google.android.exoplayer2.MediaItem)4 Test (org.junit.Test)4 Message (android.os.Message)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Intent (android.content.Intent)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 Nullable (androidx.annotation.Nullable)1 ExoPlayer (com.google.android.exoplayer2.ExoPlayer)1 Player (com.google.android.exoplayer2.Player)1 FakeClock (com.google.android.exoplayer2.testutil.FakeClock)1 ProgressHolder (com.google.android.exoplayer2.transformer.ProgressHolder)1 Transformer (com.google.android.exoplayer2.transformer.Transformer)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)1 Before (org.junit.Before)1