use of com.google.android.exoplayer2.transformer.Transformer in project ExoPlayer by google.
the class TransformerEndToEndTest method cancel_afterCompletion_doesNotThrow.
@Test
public void cancel_afterCompletion_doesNotThrow() throws Exception {
Transformer transformer = createTransformerBuilder().build();
MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_VIDEO_ONLY);
transformer.startTransformation(mediaItem, outputPath);
TransformerTestRunner.runUntilCompleted(transformer);
transformer.cancel();
}
use of com.google.android.exoplayer2.transformer.Transformer in project ExoPlayer by google.
the class TransformerEndToEndTest method startTransformation_withMultipleListeners_callsEachOnCompletion.
@Test
public void startTransformation_withMultipleListeners_callsEachOnCompletion() throws Exception {
Transformer.Listener mockListener1 = mock(Transformer.Listener.class);
Transformer.Listener mockListener2 = mock(Transformer.Listener.class);
Transformer.Listener mockListener3 = mock(Transformer.Listener.class);
Transformer transformer = createTransformerBuilder().addListener(mockListener1).addListener(mockListener2).addListener(mockListener3).build();
MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_AUDIO_VIDEO);
transformer.startTransformation(mediaItem, outputPath);
TransformerTestRunner.runUntilCompleted(transformer);
verify(mockListener1, times(1)).onTransformationCompleted(mediaItem);
verify(mockListener2, times(1)).onTransformationCompleted(mediaItem);
verify(mockListener3, times(1)).onTransformationCompleted(mediaItem);
}
use of com.google.android.exoplayer2.transformer.Transformer in project ExoPlayer by google.
the class TransformerEndToEndTest method startTransformation_withIoError_completesWithError.
@Test
public void startTransformation_withIoError_completesWithError() throws Exception {
Transformer transformer = createTransformerBuilder().build();
MediaItem mediaItem = MediaItem.fromUri("asset:///non-existing-path.mp4");
transformer.startTransformation(mediaItem, outputPath);
TransformationException exception = TransformerTestRunner.runUntilError(transformer);
assertThat(exception).hasCauseThat().hasCauseThat().isInstanceOf(IOException.class);
assertThat(exception.errorCode).isEqualTo(TransformationException.ERROR_CODE_IO_FILE_NOT_FOUND);
}
use of com.google.android.exoplayer2.transformer.Transformer in project ExoPlayer by google.
the class TransformerEndToEndTest method startTransformation_fromSpecifiedThread_completesSuccessfully.
@Test
public void startTransformation_fromSpecifiedThread_completesSuccessfully() throws Exception {
HandlerThread anotherThread = new HandlerThread("AnotherThread");
anotherThread.start();
Looper looper = anotherThread.getLooper();
Transformer transformer = createTransformerBuilder().setLooper(looper).build();
MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_AUDIO_VIDEO);
AtomicReference<Exception> exception = new AtomicReference<>();
CountDownLatch countDownLatch = new CountDownLatch(1);
new Handler(looper).post(() -> {
try {
transformer.startTransformation(mediaItem, outputPath);
TransformerTestRunner.runUntilCompleted(transformer);
} catch (Exception e) {
exception.set(e);
} finally {
countDownLatch.countDown();
}
});
countDownLatch.await();
assertThat(exception.get()).isNull();
DumpFileAsserts.assertOutput(context, testMuxer, getDumpFileName(FILE_AUDIO_VIDEO));
}
use of com.google.android.exoplayer2.transformer.Transformer in project ExoPlayer by google.
the class TransformerEndToEndTest method getProgress_knownDuration_returnsConsistentStates.
@Test
public void getProgress_knownDuration_returnsConsistentStates() throws Exception {
Transformer transformer = createTransformerBuilder().build();
MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_VIDEO_ONLY);
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);
if (progressState == PROGRESS_STATE_UNAVAILABLE) {
foundInconsistentState.set(true);
return;
}
switch(previousProgressState.get()) {
case PROGRESS_STATE_WAITING_FOR_AVAILABILITY:
break;
case 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();
}
Aggregations