use of com.google.android.exoplayer2.MediaItem 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();
}
use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.
the class DefaultMediaSourceFactoryTest method createMediaSource_withNull_usesNonNullDefaults.
@Test
public void createMediaSource_withNull_usesNonNullDefaults() {
DefaultMediaSourceFactory defaultMediaSourceFactory = new DefaultMediaSourceFactory((Context) ApplicationProvider.getApplicationContext());
MediaItem mediaItem = new MediaItem.Builder().setUri(URI_MEDIA + "/file.ism").build();
MediaSource mediaSource = defaultMediaSourceFactory.setDrmSessionManagerProvider(null).setLoadErrorHandlingPolicy(null).createMediaSource(mediaItem);
assertThat(mediaSource).isNotNull();
}
use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.
the class DefaultMediaSourceFactoryTest method createMediaSource_withManifestPath_smoothstreamingSource.
@Test
public void createMediaSource_withManifestPath_smoothstreamingSource() {
DefaultMediaSourceFactory defaultMediaSourceFactory = new DefaultMediaSourceFactory((Context) ApplicationProvider.getApplicationContext());
MediaItem mediaItem = new MediaItem.Builder().setUri(URI_MEDIA + ".ism/Manifest").build();
MediaSource mediaSource = defaultMediaSourceFactory.createMediaSource(mediaItem);
assertThat(mediaSource).isInstanceOf(SsMediaSource.class);
}
use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.
the class ExoPlayerTest method onPositionDiscontinuity_recursiveStateChange_mediaItemMaskingCorrect.
@Test
public void onPositionDiscontinuity_recursiveStateChange_mediaItemMaskingCorrect() throws Exception {
ExoPlayer player = new TestExoPlayerBuilder(context).build();
Player.Listener listener = mock(Player.Listener.class);
MediaItem[] currentMediaItems = new MediaItem[2];
int[] mediaItemCount = new int[2];
player.addListener(new Listener() {
@Override
public void onPositionDiscontinuity(PositionInfo oldPosition, PositionInfo newPosition, int reason) {
if (reason == Player.DISCONTINUITY_REASON_AUTO_TRANSITION) {
mediaItemCount[0] = player.getMediaItemCount();
currentMediaItems[0] = player.getCurrentMediaItem();
// This is called before the second listener is called.
player.removeMediaItem(/* index= */
1);
}
}
});
player.addListener(new Listener() {
@Override
public void onPositionDiscontinuity(PositionInfo oldPosition, PositionInfo newPosition, int reason) {
if (reason == Player.DISCONTINUITY_REASON_AUTO_TRANSITION) {
mediaItemCount[1] = player.getMediaItemCount();
currentMediaItems[1] = player.getCurrentMediaItem();
}
}
});
player.addListener(listener);
player.setMediaSources(ImmutableList.of(createFakeMediaSource(/* id= */
"id-0"), createFakeMediaSource(/* id= */
"id-1")));
player.prepare();
player.play();
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_ENDED);
ArgumentCaptor<PositionInfo> newPositionArgumentCaptor = ArgumentCaptor.forClass(PositionInfo.class);
InOrder inOrder = inOrder(listener);
inOrder.verify(listener).onPositionDiscontinuity(any(), newPositionArgumentCaptor.capture(), eq(Player.DISCONTINUITY_REASON_AUTO_TRANSITION));
inOrder.verify(listener).onPositionDiscontinuity(any(), newPositionArgumentCaptor.capture(), eq(Player.DISCONTINUITY_REASON_REMOVE));
// The state at auto-transition event time.
assertThat(mediaItemCount[0]).isEqualTo(2);
assertThat(currentMediaItems[0].localConfiguration.tag).isEqualTo("id-1");
// The masked state after id-1 has been removed.
assertThat(mediaItemCount[1]).isEqualTo(1);
assertThat(currentMediaItems[1].localConfiguration.tag).isEqualTo("id-0");
// PositionInfo reports the media item at event time.
assertThat(newPositionArgumentCaptor.getAllValues().get(0).mediaItem.localConfiguration.tag).isEqualTo("id-1");
assertThat(newPositionArgumentCaptor.getAllValues().get(1).mediaItem.localConfiguration.tag).isEqualTo("id-0");
player.release();
}
use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.
the class ExoPlayerTest method playingMedia_withNoMetadata_doesNotUpdateMediaMetadata.
@Test
public void playingMedia_withNoMetadata_doesNotUpdateMediaMetadata() throws Exception {
MediaMetadata mediaMetadata = new MediaMetadata.Builder().setTitle("the title").build();
ExoPlayer player = new TestExoPlayerBuilder(context).build();
MediaItem mediaItem = new MediaItem.Builder().setMediaId("id").setUri(Uri.parse("asset://android_asset/media/mp4/sample.mp4")).setMediaMetadata(mediaMetadata).build();
player.setMediaItem(mediaItem);
assertThat(player.getMediaMetadata()).isEqualTo(mediaMetadata);
player.prepare();
TestPlayerRunHelper.playUntilPosition(player, /* mediaItemIndex= */
0, /* positionMs= */
5 * C.MILLIS_PER_SECOND);
player.stop();
shadowOf(Looper.getMainLooper()).idle();
assertThat(player.getMediaMetadata()).isEqualTo(mediaMetadata);
}
Aggregations