Search in sources :

Example 31 with MediaSource

use of com.google.android.exoplayer2.source.MediaSource in project ExoPlayer by google.

the class MergingMediaSourceTest method prepareMergingMediaSource.

/**
 * Wraps the specified timelines in a {@link MergingMediaSource}, prepares it and returns the
 * merged timeline.
 */
private static Timeline prepareMergingMediaSource(boolean clipDurations, Timeline... timelines) throws IOException {
    FakeMediaSource[] mediaSources = new FakeMediaSource[timelines.length];
    for (int i = 0; i < timelines.length; i++) {
        mediaSources[i] = new FakeMediaSource(timelines[i]);
    }
    MergingMediaSource mergingMediaSource = new MergingMediaSource(/* adjustPeriodTimeOffsets= */
    false, clipDurations, mediaSources);
    MediaSourceTestRunner testRunner = new MediaSourceTestRunner(mergingMediaSource, /* allocator= */
    null);
    try {
        Timeline timeline = testRunner.prepareSource();
        testRunner.releaseSource();
        for (FakeMediaSource mediaSource : mediaSources) {
            mediaSource.assertReleased();
        }
        return timeline;
    } finally {
        testRunner.release();
    }
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) MediaSourceTestRunner(com.google.android.exoplayer2.testutil.MediaSourceTestRunner) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource)

Example 32 with MediaSource

use of com.google.android.exoplayer2.source.MediaSource 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).build();
    MediaSource mediaSource = defaultMediaSourceFactory.setDrmSessionManagerProvider(null).setLoadErrorHandlingPolicy(null).createMediaSource(mediaItem);
    assertThat(mediaSource).isNotNull();
}
Also used : AdsMediaSource(com.google.android.exoplayer2.source.ads.AdsMediaSource) MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 33 with MediaSource

use of com.google.android.exoplayer2.source.MediaSource in project ExoPlayer by google.

the class DefaultMediaSourceFactoryTest method createMediaSource_withStartPosition_isClippingMediaSource.

@Test
public void createMediaSource_withStartPosition_isClippingMediaSource() {
    DefaultMediaSourceFactory defaultMediaSourceFactory = new DefaultMediaSourceFactory((Context) ApplicationProvider.getApplicationContext());
    MediaItem mediaItem = new MediaItem.Builder().setUri(URI_MEDIA).setClippingConfiguration(new MediaItem.ClippingConfiguration.Builder().setStartPositionMs(1000L).build()).build();
    MediaSource mediaSource = defaultMediaSourceFactory.createMediaSource(mediaItem);
    assertThat(mediaSource).isInstanceOf(ClippingMediaSource.class);
}
Also used : AdsMediaSource(com.google.android.exoplayer2.source.ads.AdsMediaSource) MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 34 with MediaSource

use of com.google.android.exoplayer2.source.MediaSource in project ExoPlayer by google.

the class DefaultMediaSourceFactoryTest method createMediaSource_fromMediaItem_returnsSameMediaItemInstance.

@Test
public void createMediaSource_fromMediaItem_returnsSameMediaItemInstance() {
    DefaultMediaSourceFactory defaultMediaSourceFactory = new DefaultMediaSourceFactory((Context) ApplicationProvider.getApplicationContext());
    MediaItem mediaItem = new MediaItem.Builder().setUri(URI_MEDIA).build();
    MediaSource mediaSource = defaultMediaSourceFactory.createMediaSource(mediaItem);
    assertThat(mediaSource.getMediaItem()).isSameInstanceAs(mediaItem);
}
Also used : AdsMediaSource(com.google.android.exoplayer2.source.ads.AdsMediaSource) MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 35 with MediaSource

use of com.google.android.exoplayer2.source.MediaSource in project ExoPlayer by google.

the class DefaultMediaSourceFactoryTest method createMediaSource_withoutMimeType_progressiveSource.

@Test
public void createMediaSource_withoutMimeType_progressiveSource() {
    DefaultMediaSourceFactory defaultMediaSourceFactory = new DefaultMediaSourceFactory((Context) ApplicationProvider.getApplicationContext());
    MediaItem mediaItem = new MediaItem.Builder().setUri(URI_MEDIA).build();
    MediaSource mediaSource = defaultMediaSourceFactory.createMediaSource(mediaItem);
    assertThat(mediaSource).isInstanceOf(ProgressiveMediaSource.class);
}
Also used : AdsMediaSource(com.google.android.exoplayer2.source.ads.AdsMediaSource) MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)182 MediaSource (com.google.android.exoplayer2.source.MediaSource)117 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)117 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)74 MediaItem (com.google.android.exoplayer2.MediaItem)70 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)70 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)69 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)60 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)51 CompositeMediaSource (com.google.android.exoplayer2.source.CompositeMediaSource)51 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)51 ServerSideAdInsertionMediaSource (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource)50 FakeAdaptiveMediaSource (com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource)50 ExoPlayerTestRunner (com.google.android.exoplayer2.testutil.ExoPlayerTestRunner)45 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)39 NoUidTimeline (com.google.android.exoplayer2.testutil.NoUidTimeline)39 Timeline (com.google.android.exoplayer2.Timeline)35 PlayerRunnable (com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable)34 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)28 TransferListener (com.google.android.exoplayer2.upstream.TransferListener)25