Search in sources :

Example 1 with AssetDataSource

use of androidx.media3.datasource.AssetDataSource in project media by androidx.

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 : 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) DefaultLoadErrorHandlingPolicy(androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) DefaultAllocator(androidx.media3.exoplayer.upstream.DefaultAllocator) ApplicationProvider(androidx.test.core.app.ApplicationProvider) DrmSessionManager(androidx.media3.exoplayer.drm.DrmSessionManager) C(androidx.media3.common.C) Mp4Extractor(androidx.media3.extractor.mp4.Mp4Extractor) DrmSessionEventListener(androidx.media3.exoplayer.drm.DrmSessionEventListener) PlayerId(androidx.media3.exoplayer.analytics.PlayerId) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId) AssetDataSource(androidx.media3.datasource.AssetDataSource) RobolectricUtil.runMainLooperUntil(androidx.media3.test.utils.robolectric.RobolectricUtil.runMainLooperUntil) AssetDataSource(androidx.media3.datasource.AssetDataSource) DefaultLoadErrorHandlingPolicy(androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId) DefaultAllocator(androidx.media3.exoplayer.upstream.DefaultAllocator)

Aggregations

Uri (android.net.Uri)1 C (androidx.media3.common.C)1 AssetDataSource (androidx.media3.datasource.AssetDataSource)1 PlayerId (androidx.media3.exoplayer.analytics.PlayerId)1 DrmSessionEventListener (androidx.media3.exoplayer.drm.DrmSessionEventListener)1 DrmSessionManager (androidx.media3.exoplayer.drm.DrmSessionManager)1 MediaPeriodId (androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)1 DefaultAllocator (androidx.media3.exoplayer.upstream.DefaultAllocator)1 DefaultLoadErrorHandlingPolicy (androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy)1 Mp4Extractor (androidx.media3.extractor.mp4.Mp4Extractor)1 RobolectricUtil.runMainLooperUntil (androidx.media3.test.utils.robolectric.RobolectricUtil.runMainLooperUntil)1 ApplicationProvider (androidx.test.core.app.ApplicationProvider)1 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)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