Search in sources :

Example 1 with AssetDataSource

use of com.google.android.exoplayer2.upstream.AssetDataSource in project ExoPlayer by google.

the class ProgressiveMediaPeriodTest method testExtractorsUpdatesSourceInfoBeforeOnPreparedCallback.

private static void testExtractorsUpdatesSourceInfoBeforeOnPreparedCallback(ProgressiveMediaExtractor extractor) throws TimeoutException {
    AtomicBoolean sourceInfoRefreshCalled = new AtomicBoolean(false);
    ProgressiveMediaPeriod.Listener sourceInfoRefreshListener = (durationUs, isSeekable, isLive) -> sourceInfoRefreshCalled.set(true);
    MediaPeriodId mediaPeriodId = new MediaPeriodId(/* periodUid= */
    new Object());
    ProgressiveMediaPeriod mediaPeriod = new ProgressiveMediaPeriod(Uri.parse("asset://android_asset/media/mp4/sample.mp4"), new AssetDataSource(ApplicationProvider.getApplicationContext()), extractor, DrmSessionManager.DRM_UNSUPPORTED, new DrmSessionEventListener.EventDispatcher().withParameters(/* windowIndex= */
    0, mediaPeriodId), new DefaultLoadErrorHandlingPolicy(), new MediaSourceEventListener.EventDispatcher().withParameters(/* windowIndex= */
    0, mediaPeriodId, /* mediaTimeOffsetMs= */
    0), sourceInfoRefreshListener, new DefaultAllocator(/* trimOnReset= */
    true, C.DEFAULT_BUFFER_SEGMENT_SIZE), /* customCacheKey= */
    null, ProgressiveMediaSource.DEFAULT_LOADING_CHECK_INTERVAL_BYTES);
    AtomicBoolean prepareCallbackCalled = new AtomicBoolean(false);
    AtomicBoolean sourceInfoRefreshCalledBeforeOnPrepared = new AtomicBoolean(false);
    mediaPeriod.prepare(new MediaPeriod.Callback() {

        @Override
        public void onPrepared(MediaPeriod mediaPeriod) {
            sourceInfoRefreshCalledBeforeOnPrepared.set(sourceInfoRefreshCalled.get());
            prepareCallbackCalled.set(true);
        }

        @Override
        public void onContinueLoadingRequested(MediaPeriod source) {
            source.continueLoading(/* positionUs= */
            0);
        }
    }, /* positionUs= */
    0);
    runMainLooperUntil(prepareCallbackCalled::get);
    mediaPeriod.release();
    assertThat(sourceInfoRefreshCalledBeforeOnPrepared.get()).isTrue();
}
Also used : RobolectricUtil.runMainLooperUntil(com.google.android.exoplayer2.robolectric.RobolectricUtil.runMainLooperUntil) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) AssetDataSource(com.google.android.exoplayer2.upstream.AssetDataSource) DefaultLoadErrorHandlingPolicy(com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy) Uri(android.net.Uri) RunWith(org.junit.runner.RunWith) TimeoutException(java.util.concurrent.TimeoutException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) ApplicationProvider(androidx.test.core.app.ApplicationProvider) Mp4Extractor(com.google.android.exoplayer2.extractor.mp4.Mp4Extractor) PlayerId(com.google.android.exoplayer2.analytics.PlayerId) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) DefaultAllocator(com.google.android.exoplayer2.upstream.DefaultAllocator) C(com.google.android.exoplayer2.C) AssetDataSource(com.google.android.exoplayer2.upstream.AssetDataSource) DefaultLoadErrorHandlingPolicy(com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) DefaultAllocator(com.google.android.exoplayer2.upstream.DefaultAllocator)

Aggregations

Uri (android.net.Uri)1 ApplicationProvider (androidx.test.core.app.ApplicationProvider)1 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)1 C (com.google.android.exoplayer2.C)1 PlayerId (com.google.android.exoplayer2.analytics.PlayerId)1 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)1 DrmSessionManager (com.google.android.exoplayer2.drm.DrmSessionManager)1 Mp4Extractor (com.google.android.exoplayer2.extractor.mp4.Mp4Extractor)1 RobolectricUtil.runMainLooperUntil (com.google.android.exoplayer2.robolectric.RobolectricUtil.runMainLooperUntil)1 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)1 AssetDataSource (com.google.android.exoplayer2.upstream.AssetDataSource)1 DefaultAllocator (com.google.android.exoplayer2.upstream.DefaultAllocator)1 DefaultLoadErrorHandlingPolicy (com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Test (org.junit.Test)1 RunWith (org.junit.runner.RunWith)1