Search in sources :

Example 6 with LoadErrorHandlingPolicy

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

the class DefaultDashChunkSourceTest method getNextChunk_onChunkLoadErrorTrackExclusionEnabled_correctFallbackBehavior.

@Test
public void getNextChunk_onChunkLoadErrorTrackExclusionEnabled_correctFallbackBehavior() throws Exception {
    DefaultLoadErrorHandlingPolicy loadErrorHandlingPolicy = new DefaultLoadErrorHandlingPolicy() {

        @Override
        public FallbackSelection getFallbackSelectionFor(FallbackOptions fallbackOptions, LoadErrorInfo loadErrorInfo) {
            // Exclude tracks only.
            return new FallbackSelection(FALLBACK_TYPE_TRACK, DefaultLoadErrorHandlingPolicy.DEFAULT_TRACK_EXCLUSION_MS);
        }
    };
    DashChunkSource chunkSource = createDashChunkSource(/* numberOfTracks= */
    4);
    ChunkHolder output = new ChunkHolder();
    List<Chunk> chunks = new ArrayList<>();
    boolean requestReplacementChunk = true;
    while (requestReplacementChunk) {
        chunkSource.getNextChunk(/* playbackPositionUs= */
        0, /* loadPositionUs= */
        0, /* queue= */
        ImmutableList.of(), output);
        chunks.add(output.chunk);
        requestReplacementChunk = chunkSource.onChunkLoadError(checkNotNull(output.chunk), /* cancelable= */
        true, createFakeLoadErrorInfo(output.chunk.dataSpec, /* httpResponseCode= */
        404, /* errorCount= */
        1), loadErrorHandlingPolicy);
    }
    assertThat(Lists.transform(chunks, (chunk) -> chunk.dataSpec.uri.toString())).containsExactly("http://video.com/baseUrl/a/video/video_0_700000.m4s", "http://video.com/baseUrl/a/video/video_0_452000.m4s", "http://video.com/baseUrl/a/video/video_0_250000.m4s", "http://video.com/baseUrl/a/video/video_0_1300000.m4s").inOrder();
}
Also used : Util(com.google.android.exoplayer2.util.Util) LoadEventInfo(com.google.android.exoplayer2.source.LoadEventInfo) Uri(android.net.Uri) RunWith(org.junit.runner.RunWith) SystemClock(android.os.SystemClock) Random(java.util.Random) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) TestUtil(com.google.android.exoplayer2.testutil.TestUtil) ApplicationProvider(androidx.test.core.app.ApplicationProvider) ArrayList(java.util.ArrayList) Format(com.google.android.exoplayer2.Format) FixedTrackSelection(com.google.android.exoplayer2.trackselection.FixedTrackSelection) PlayerId(com.google.android.exoplayer2.analytics.PlayerId) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) DashManifestParser(com.google.android.exoplayer2.source.dash.manifest.DashManifestParser) Duration(java.time.Duration) AdaptiveTrackSelection(com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection) C(com.google.android.exoplayer2.C) BundledChunkExtractor(com.google.android.exoplayer2.source.chunk.BundledChunkExtractor) DefaultLoadErrorHandlingPolicy(com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy) DEFAULT_LOCATION_EXCLUSION_MS(com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy.DEFAULT_LOCATION_EXCLUSION_MS) ImmutableMap(com.google.common.collect.ImmutableMap) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) DataSpec(com.google.android.exoplayer2.upstream.DataSpec) IOException(java.io.IOException) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) HttpDataSource(com.google.android.exoplayer2.upstream.HttpDataSource) ChunkHolder(com.google.android.exoplayer2.source.chunk.ChunkHolder) FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) DefaultBandwidthMeter(com.google.android.exoplayer2.upstream.DefaultBandwidthMeter) List(java.util.List) Nullable(androidx.annotation.Nullable) Chunk(com.google.android.exoplayer2.source.chunk.Chunk) DashManifest(com.google.android.exoplayer2.source.dash.manifest.DashManifest) LoadErrorHandlingPolicy(com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy) ShadowSystemClock(org.robolectric.shadows.ShadowSystemClock) MediaLoadData(com.google.android.exoplayer2.source.MediaLoadData) Assertions.checkNotNull(com.google.android.exoplayer2.util.Assertions.checkNotNull) Assertions(com.google.android.exoplayer2.util.Assertions) LoaderErrorThrower(com.google.android.exoplayer2.upstream.LoaderErrorThrower) DefaultLoadErrorHandlingPolicy(com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy) ChunkHolder(com.google.android.exoplayer2.source.chunk.ChunkHolder) ArrayList(java.util.ArrayList) Chunk(com.google.android.exoplayer2.source.chunk.Chunk) Test(org.junit.Test)

Example 7 with LoadErrorHandlingPolicy

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

the class SsMediaSource method createPeriod.

@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long startPositionUs) {
    MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher = createEventDispatcher(id);
    DrmSessionEventListener.EventDispatcher drmEventDispatcher = createDrmEventDispatcher(id);
    SsMediaPeriod period = new SsMediaPeriod(manifest, chunkSourceFactory, mediaTransferListener, compositeSequenceableLoaderFactory, drmSessionManager, drmEventDispatcher, loadErrorHandlingPolicy, mediaSourceEventDispatcher, manifestLoaderErrorThrower, allocator);
    mediaPeriods.add(period);
    return period;
}
Also used : EventDispatcher(com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher) MediaSourceEventListener(com.google.android.exoplayer2.source.MediaSourceEventListener) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener)

Example 8 with LoadErrorHandlingPolicy

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

the class DashMediaSource method createPeriod.

@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long startPositionUs) {
    int periodIndex = (Integer) id.periodUid - firstPeriodId;
    MediaSourceEventListener.EventDispatcher periodEventDispatcher = createEventDispatcher(id, manifest.getPeriod(periodIndex).startMs);
    DrmSessionEventListener.EventDispatcher drmEventDispatcher = createDrmEventDispatcher(id);
    DashMediaPeriod mediaPeriod = new DashMediaPeriod(firstPeriodId + periodIndex, manifest, baseUrlExclusionList, periodIndex, chunkSourceFactory, mediaTransferListener, drmSessionManager, drmEventDispatcher, loadErrorHandlingPolicy, periodEventDispatcher, elapsedRealtimeOffsetMs, manifestLoadErrorThrower, allocator, compositeSequenceableLoaderFactory, playerEmsgCallback, getPlayerId());
    periodsById.put(mediaPeriod.id, mediaPeriod);
    return mediaPeriod;
}
Also used : EventDispatcher(com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher) MediaSourceEventListener(com.google.android.exoplayer2.source.MediaSourceEventListener) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener)

Example 9 with LoadErrorHandlingPolicy

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

the class DefaultMediaSourceFactory method createMediaSource.

@Override
public MediaSource createMediaSource(MediaItem mediaItem) {
    Assertions.checkNotNull(mediaItem.localConfiguration);
    @Nullable String scheme = mediaItem.localConfiguration.uri.getScheme();
    if (scheme != null && scheme.equals(C.SSAI_SCHEME)) {
        return checkNotNull(serverSideAdInsertionMediaSourceFactory).createMediaSource(mediaItem);
    }
    @C.ContentType int type = Util.inferContentTypeForUriAndMimeType(mediaItem.localConfiguration.uri, mediaItem.localConfiguration.mimeType);
    @Nullable MediaSource.Factory mediaSourceFactory = delegateFactoryLoader.getMediaSourceFactory(type);
    checkStateNotNull(mediaSourceFactory, "No suitable media source factory found for content type: " + type);
    MediaItem.LiveConfiguration.Builder liveConfigurationBuilder = mediaItem.liveConfiguration.buildUpon();
    if (mediaItem.liveConfiguration.targetOffsetMs == C.TIME_UNSET) {
        liveConfigurationBuilder.setTargetOffsetMs(liveTargetOffsetMs);
    }
    if (mediaItem.liveConfiguration.minPlaybackSpeed == C.RATE_UNSET) {
        liveConfigurationBuilder.setMinPlaybackSpeed(liveMinSpeed);
    }
    if (mediaItem.liveConfiguration.maxPlaybackSpeed == C.RATE_UNSET) {
        liveConfigurationBuilder.setMaxPlaybackSpeed(liveMaxSpeed);
    }
    if (mediaItem.liveConfiguration.minOffsetMs == C.TIME_UNSET) {
        liveConfigurationBuilder.setMinOffsetMs(liveMinOffsetMs);
    }
    if (mediaItem.liveConfiguration.maxOffsetMs == C.TIME_UNSET) {
        liveConfigurationBuilder.setMaxOffsetMs(liveMaxOffsetMs);
    }
    MediaItem.LiveConfiguration liveConfiguration = liveConfigurationBuilder.build();
    // Make sure to retain the very same media item instance, if no value needs to be overridden.
    if (!liveConfiguration.equals(mediaItem.liveConfiguration)) {
        mediaItem = mediaItem.buildUpon().setLiveConfiguration(liveConfiguration).build();
    }
    MediaSource mediaSource = mediaSourceFactory.createMediaSource(mediaItem);
    List<MediaItem.SubtitleConfiguration> subtitleConfigurations = castNonNull(mediaItem.localConfiguration).subtitleConfigurations;
    if (!subtitleConfigurations.isEmpty()) {
        MediaSource[] mediaSources = new MediaSource[subtitleConfigurations.size() + 1];
        mediaSources[0] = mediaSource;
        for (int i = 0; i < subtitleConfigurations.size(); i++) {
            if (useProgressiveMediaSourceForSubtitles) {
                Format format = new Format.Builder().setSampleMimeType(subtitleConfigurations.get(i).mimeType).setLanguage(subtitleConfigurations.get(i).language).setSelectionFlags(subtitleConfigurations.get(i).selectionFlags).setRoleFlags(subtitleConfigurations.get(i).roleFlags).setLabel(subtitleConfigurations.get(i).label).setId(subtitleConfigurations.get(i).id).build();
                ExtractorsFactory extractorsFactory = () -> new Extractor[] { SubtitleDecoderFactory.DEFAULT.supportsFormat(format) ? new SubtitleExtractor(SubtitleDecoderFactory.DEFAULT.createDecoder(format), format) : new UnknownSubtitlesExtractor(format) };
                mediaSources[i + 1] = new ProgressiveMediaSource.Factory(dataSourceFactory, extractorsFactory).setLoadErrorHandlingPolicy(loadErrorHandlingPolicy).createMediaSource(MediaItem.fromUri(subtitleConfigurations.get(i).uri.toString()));
            } else {
                mediaSources[i + 1] = new SingleSampleMediaSource.Factory(dataSourceFactory).setLoadErrorHandlingPolicy(loadErrorHandlingPolicy).createMediaSource(subtitleConfigurations.get(i), /* durationUs= */
                C.TIME_UNSET);
            }
        }
        mediaSource = new MergingMediaSource(mediaSources);
    }
    return maybeWrapWithAdsMediaSource(mediaItem, maybeClipMediaSource(mediaItem, mediaSource));
}
Also used : SubtitleExtractor(com.google.android.exoplayer2.text.SubtitleExtractor) Format(com.google.android.exoplayer2.Format) AdsMediaSource(com.google.android.exoplayer2.source.ads.AdsMediaSource) ExtractorsFactory(com.google.android.exoplayer2.extractor.ExtractorsFactory) DefaultExtractorsFactory(com.google.android.exoplayer2.extractor.DefaultExtractorsFactory) MediaItem(com.google.android.exoplayer2.MediaItem) Extractor(com.google.android.exoplayer2.extractor.Extractor) SubtitleExtractor(com.google.android.exoplayer2.text.SubtitleExtractor) Nullable(androidx.annotation.Nullable)

Example 10 with LoadErrorHandlingPolicy

use of com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy in project HybridMediaPlayer by mkaflowski.

the class ExoMediaPlayer method setDataSource.

public void setDataSource(List<MediaSourceInfo> normalSources, List<MediaSourceInfo> castSources) {
    if (exoPlayer != null)
        exoPlayer.stop();
    String userAgent = Util.getUserAgent(context, "yourApplicationName");
    DefaultHttpDataSourceFactory httpDataSourceFactory = new DefaultHttpDataSourceFactory(userAgent, null, /* listener */
    DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS, DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS, true);
    // Produces DataSource instances through which media data is loaded.
    DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context, null, httpDataSourceFactory);
    // Produces Extractor instances for parsing the media data.
    ExtractorsFactory extractorsFactory = new SeekableExtractorsFactory();
    MediaSource[] sources = new MediaSource[normalSources.size()];
    for (int i = 0; i < normalSources.size(); i++) {
        // This is the MediaSource representing the media to be played.
        ProgressiveMediaSource.Factory factory = new ProgressiveMediaSource.Factory(dataSourceFactory);
        if (loadErrorHandlingPolicy != null)
            factory.setLoadErrorHandlingPolicy(loadErrorHandlingPolicy);
        sources[i] = factory.createMediaSource(Uri.parse(normalSources.get(i).getUrl()));
    }
    exoMediaSource = new ConcatenatingMediaSource(sources);
    prepareCastMediaSourceInfoList(castSources);
}
Also used : ProgressiveMediaSource(com.google.android.exoplayer2.source.ProgressiveMediaSource) DefaultHttpDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory) DefaultDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultDataSourceFactory) ExtractorsFactory(com.google.android.exoplayer2.extractor.ExtractorsFactory) DataSource(com.google.android.exoplayer2.upstream.DataSource) DefaultHttpDataSource(com.google.android.exoplayer2.upstream.DefaultHttpDataSource) ProgressiveMediaSource(com.google.android.exoplayer2.source.ProgressiveMediaSource) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) DefaultHttpDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory) ExtractorsFactory(com.google.android.exoplayer2.extractor.ExtractorsFactory) DefaultDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultDataSourceFactory) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource)

Aggregations

Nullable (androidx.annotation.Nullable)5 Format (com.google.android.exoplayer2.Format)4 LoadEventInfo (com.google.android.exoplayer2.source.LoadEventInfo)3 MediaLoadData (com.google.android.exoplayer2.source.MediaLoadData)3 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)3 ChunkHolder (com.google.android.exoplayer2.source.chunk.ChunkHolder)3 DefaultLoadErrorHandlingPolicy (com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy)3 Uri (android.net.Uri)2 SystemClock (android.os.SystemClock)2 ApplicationProvider (androidx.test.core.app.ApplicationProvider)2 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)2 C (com.google.android.exoplayer2.C)2 PlayerId (com.google.android.exoplayer2.analytics.PlayerId)2 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)2 ExtractorsFactory (com.google.android.exoplayer2.extractor.ExtractorsFactory)2 MediaSourceEventListener (com.google.android.exoplayer2.source.MediaSourceEventListener)2 EventDispatcher (com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher)2 BundledChunkExtractor (com.google.android.exoplayer2.source.chunk.BundledChunkExtractor)2 Chunk (com.google.android.exoplayer2.source.chunk.Chunk)2 DashManifest (com.google.android.exoplayer2.source.dash.manifest.DashManifest)2