Search in sources :

Example 1 with MediaLoadData

use of androidx.media3.exoplayer.source.MediaLoadData in project media by androidx.

the class SingleSampleMediaPeriod method onLoadError.

@Override
public LoadErrorAction onLoadError(SourceLoadable loadable, long elapsedRealtimeMs, long loadDurationMs, IOException error, int errorCount) {
    StatsDataSource dataSource = loadable.dataSource;
    LoadEventInfo loadEventInfo = new LoadEventInfo(loadable.loadTaskId, loadable.dataSpec, dataSource.getLastOpenedUri(), dataSource.getLastResponseHeaders(), elapsedRealtimeMs, loadDurationMs, dataSource.getBytesRead());
    MediaLoadData mediaLoadData = new MediaLoadData(C.DATA_TYPE_MEDIA, C.TRACK_TYPE_UNKNOWN, format, C.SELECTION_REASON_UNKNOWN, /* trackSelectionData= */
    null, /* mediaStartTimeMs= */
    0, Util.usToMs(durationUs));
    long retryDelay = loadErrorHandlingPolicy.getRetryDelayMsFor(new LoadErrorInfo(loadEventInfo, mediaLoadData, error, errorCount));
    boolean errorCanBePropagated = retryDelay == C.TIME_UNSET || errorCount >= loadErrorHandlingPolicy.getMinimumLoadableRetryCount(C.DATA_TYPE_MEDIA);
    LoadErrorAction action;
    if (treatLoadErrorsAsEndOfStream && errorCanBePropagated) {
        Log.w(TAG, "Loading failed, treating as end-of-stream.", error);
        loadingFinished = true;
        action = Loader.DONT_RETRY;
    } else {
        action = retryDelay != C.TIME_UNSET ? Loader.createRetryAction(/* resetErrorCount= */
        false, retryDelay) : Loader.DONT_RETRY_FATAL;
    }
    boolean wasCanceled = !action.isRetry();
    eventDispatcher.loadError(loadEventInfo, C.DATA_TYPE_MEDIA, C.TRACK_TYPE_UNKNOWN, format, C.SELECTION_REASON_UNKNOWN, /* trackSelectionData= */
    null, /* mediaStartTimeUs= */
    0, durationUs, error, wasCanceled);
    if (wasCanceled) {
        loadErrorHandlingPolicy.onLoadTaskConcluded(loadable.loadTaskId);
    }
    return action;
}
Also used : LoadErrorInfo(androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy.LoadErrorInfo) StatsDataSource(androidx.media3.datasource.StatsDataSource) LoadErrorAction(androidx.media3.exoplayer.upstream.Loader.LoadErrorAction)

Example 2 with MediaLoadData

use of androidx.media3.exoplayer.source.MediaLoadData in project media by androidx.

the class DashMediaSource method onManifestLoadError.

/* package */
LoadErrorAction onManifestLoadError(ParsingLoadable<DashManifest> loadable, long elapsedRealtimeMs, long loadDurationMs, IOException error, int errorCount) {
    LoadEventInfo loadEventInfo = new LoadEventInfo(loadable.loadTaskId, loadable.dataSpec, loadable.getUri(), loadable.getResponseHeaders(), elapsedRealtimeMs, loadDurationMs, loadable.bytesLoaded());
    MediaLoadData mediaLoadData = new MediaLoadData(loadable.type);
    LoadErrorInfo loadErrorInfo = new LoadErrorInfo(loadEventInfo, mediaLoadData, error, errorCount);
    long retryDelayMs = loadErrorHandlingPolicy.getRetryDelayMsFor(loadErrorInfo);
    LoadErrorAction loadErrorAction = retryDelayMs == C.TIME_UNSET ? Loader.DONT_RETRY_FATAL : Loader.createRetryAction(/* resetErrorCount= */
    false, retryDelayMs);
    boolean wasCanceled = !loadErrorAction.isRetry();
    manifestEventDispatcher.loadError(loadEventInfo, loadable.type, error, wasCanceled);
    if (wasCanceled) {
        loadErrorHandlingPolicy.onLoadTaskConcluded(loadable.loadTaskId);
    }
    return loadErrorAction;
}
Also used : LoadEventInfo(androidx.media3.exoplayer.source.LoadEventInfo) MediaLoadData(androidx.media3.exoplayer.source.MediaLoadData) LoadErrorInfo(androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy.LoadErrorInfo) LoadErrorAction(androidx.media3.exoplayer.upstream.Loader.LoadErrorAction)

Example 3 with MediaLoadData

use of androidx.media3.exoplayer.source.MediaLoadData in project media by androidx.

the class DefaultDashChunkSourceTest method createFakeLoadErrorInfo.

private LoadErrorHandlingPolicy.LoadErrorInfo createFakeLoadErrorInfo(DataSpec dataSpec, int httpResponseCode, int errorCount) {
    LoadEventInfo loadEventInfo = new LoadEventInfo(/* loadTaskId= */
    0, dataSpec, SystemClock.elapsedRealtime());
    MediaLoadData mediaLoadData = new MediaLoadData(C.DATA_TYPE_MEDIA);
    HttpDataSource.InvalidResponseCodeException invalidResponseCodeException = new HttpDataSource.InvalidResponseCodeException(httpResponseCode, /* responseMessage= */
    null, /* cause= */
    null, ImmutableMap.of(), dataSpec, new byte[0]);
    return new LoadErrorHandlingPolicy.LoadErrorInfo(loadEventInfo, mediaLoadData, invalidResponseCodeException, errorCount);
}
Also used : LoadEventInfo(androidx.media3.exoplayer.source.LoadEventInfo) MediaLoadData(androidx.media3.exoplayer.source.MediaLoadData) HttpDataSource(androidx.media3.datasource.HttpDataSource)

Example 4 with MediaLoadData

use of androidx.media3.exoplayer.source.MediaLoadData in project media by androidx.

the class HlsSampleStreamWrapper method onLoadError.

@Override
public LoadErrorAction onLoadError(Chunk loadable, long elapsedRealtimeMs, long loadDurationMs, IOException error, int errorCount) {
    boolean isMediaChunk = isMediaChunk(loadable);
    if (isMediaChunk && !((HlsMediaChunk) loadable).isPublished() && error instanceof HttpDataSource.InvalidResponseCodeException) {
        int responseCode = ((HttpDataSource.InvalidResponseCodeException) error).responseCode;
        if (responseCode == 410 || responseCode == 404) {
            // streams with HTTP 410 (Gone) also.
            return Loader.RETRY;
        }
    }
    long bytesLoaded = loadable.bytesLoaded();
    boolean exclusionSucceeded = false;
    LoadEventInfo loadEventInfo = new LoadEventInfo(loadable.loadTaskId, loadable.dataSpec, loadable.getUri(), loadable.getResponseHeaders(), elapsedRealtimeMs, loadDurationMs, bytesLoaded);
    MediaLoadData mediaLoadData = new MediaLoadData(loadable.type, trackType, loadable.trackFormat, loadable.trackSelectionReason, loadable.trackSelectionData, Util.usToMs(loadable.startTimeUs), Util.usToMs(loadable.endTimeUs));
    LoadErrorInfo loadErrorInfo = new LoadErrorInfo(loadEventInfo, mediaLoadData, error, errorCount);
    LoadErrorAction loadErrorAction;
    @Nullable LoadErrorHandlingPolicy.FallbackSelection fallbackSelection = loadErrorHandlingPolicy.getFallbackSelectionFor(createFallbackOptions(chunkSource.getTrackSelection()), loadErrorInfo);
    if (fallbackSelection != null && fallbackSelection.type == LoadErrorHandlingPolicy.FALLBACK_TYPE_TRACK) {
        exclusionSucceeded = chunkSource.maybeExcludeTrack(loadable, fallbackSelection.exclusionDurationMs);
    }
    if (exclusionSucceeded) {
        if (isMediaChunk && bytesLoaded == 0) {
            HlsMediaChunk removed = mediaChunks.remove(mediaChunks.size() - 1);
            Assertions.checkState(removed == loadable);
            if (mediaChunks.isEmpty()) {
                pendingResetPositionUs = lastSeekPositionUs;
            } else {
                Iterables.getLast(mediaChunks).invalidateExtractor();
            }
        }
        loadErrorAction = Loader.DONT_RETRY;
    } else /* did not exclude */
    {
        long retryDelayMs = loadErrorHandlingPolicy.getRetryDelayMsFor(loadErrorInfo);
        loadErrorAction = retryDelayMs != C.TIME_UNSET ? Loader.createRetryAction(/* resetErrorCount= */
        false, retryDelayMs) : Loader.DONT_RETRY_FATAL;
    }
    boolean wasCanceled = !loadErrorAction.isRetry();
    mediaSourceEventDispatcher.loadError(loadEventInfo, loadable.type, trackType, loadable.trackFormat, loadable.trackSelectionReason, loadable.trackSelectionData, loadable.startTimeUs, loadable.endTimeUs, error, wasCanceled);
    if (wasCanceled) {
        loadingChunk = null;
        loadErrorHandlingPolicy.onLoadTaskConcluded(loadable.loadTaskId);
    }
    if (exclusionSucceeded) {
        if (!prepared) {
            continueLoading(lastSeekPositionUs);
        } else {
            callback.onContinueLoadingRequested(this);
        }
    }
    return loadErrorAction;
}
Also used : MediaLoadData(androidx.media3.exoplayer.source.MediaLoadData) LoadErrorInfo(androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy.LoadErrorInfo) LoadErrorHandlingPolicy(androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy) LoadEventInfo(androidx.media3.exoplayer.source.LoadEventInfo) HttpDataSource(androidx.media3.datasource.HttpDataSource) Nullable(androidx.annotation.Nullable) LoadErrorAction(androidx.media3.exoplayer.upstream.Loader.LoadErrorAction)

Example 5 with MediaLoadData

use of androidx.media3.exoplayer.source.MediaLoadData in project media by androidx.

the class FakeMediaSource method finishSourcePreparation.

private void finishSourcePreparation(boolean sendManifestLoadEvents) {
    refreshSourceInfo(Assertions.checkStateNotNull(timeline));
    if (!timeline.isEmpty() && sendManifestLoadEvents) {
        MediaLoadData mediaLoadData = new MediaLoadData(C.DATA_TYPE_MANIFEST, C.TRACK_TYPE_UNKNOWN, /* trackFormat= */
        null, C.SELECTION_REASON_UNKNOWN, /* trackSelectionData= */
        null, /* mediaStartTimeMs= */
        C.TIME_UNSET, /* mediaEndTimeMs = */
        C.TIME_UNSET);
        long elapsedRealTimeMs = SystemClock.elapsedRealtime();
        MediaSourceEventListener.EventDispatcher eventDispatcher = createEventDispatcher(/* mediaPeriodId= */
        null);
        long loadTaskId = LoadEventInfo.getNewId();
        eventDispatcher.loadStarted(new LoadEventInfo(loadTaskId, FAKE_DATA_SPEC, FAKE_DATA_SPEC.uri, /* responseHeaders= */
        ImmutableMap.of(), elapsedRealTimeMs, /* loadDurationMs= */
        0, /* bytesLoaded= */
        0), mediaLoadData);
        eventDispatcher.loadCompleted(new LoadEventInfo(loadTaskId, FAKE_DATA_SPEC, FAKE_DATA_SPEC.uri, /* responseHeaders= */
        ImmutableMap.of(), elapsedRealTimeMs, /* loadDurationMs= */
        0, /* bytesLoaded= */
        MANIFEST_LOAD_BYTES), mediaLoadData);
    }
}
Also used : MediaLoadData(androidx.media3.exoplayer.source.MediaLoadData) LoadEventInfo(androidx.media3.exoplayer.source.LoadEventInfo) MediaSourceEventListener(androidx.media3.exoplayer.source.MediaSourceEventListener)

Aggregations

LoadEventInfo (androidx.media3.exoplayer.source.LoadEventInfo)7 MediaLoadData (androidx.media3.exoplayer.source.MediaLoadData)7 LoadErrorInfo (androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy.LoadErrorInfo)7 EventTime (androidx.media3.exoplayer.analytics.AnalyticsListener.EventTime)6 LoadErrorAction (androidx.media3.exoplayer.upstream.Loader.LoadErrorAction)6 Nullable (androidx.annotation.Nullable)2 HttpDataSource (androidx.media3.datasource.HttpDataSource)2 StatsDataSource (androidx.media3.datasource.StatsDataSource)2 Timeline (androidx.media3.common.Timeline)1 MediaPeriod (androidx.media3.exoplayer.source.MediaPeriod)1 MediaPeriodId (androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)1 MediaSourceEventListener (androidx.media3.exoplayer.source.MediaSourceEventListener)1 LoadErrorHandlingPolicy (androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy)1 HashSet (java.util.HashSet)1