Search in sources :

Example 6 with StatsDataSource

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

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(com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy.LoadErrorInfo) StatsDataSource(com.google.android.exoplayer2.upstream.StatsDataSource) LoadErrorAction(com.google.android.exoplayer2.upstream.Loader.LoadErrorAction)

Example 7 with StatsDataSource

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

the class SingleSampleMediaPeriod method onLoadCanceled.

@Override
public void onLoadCanceled(SourceLoadable loadable, long elapsedRealtimeMs, long loadDurationMs, boolean released) {
    StatsDataSource dataSource = loadable.dataSource;
    LoadEventInfo loadEventInfo = new LoadEventInfo(loadable.loadTaskId, loadable.dataSpec, dataSource.getLastOpenedUri(), dataSource.getLastResponseHeaders(), elapsedRealtimeMs, loadDurationMs, dataSource.getBytesRead());
    loadErrorHandlingPolicy.onLoadTaskConcluded(loadable.loadTaskId);
    eventDispatcher.loadCanceled(loadEventInfo, C.DATA_TYPE_MEDIA, C.TRACK_TYPE_UNKNOWN, /* trackFormat= */
    null, C.SELECTION_REASON_UNKNOWN, /* trackSelectionData= */
    null, /* mediaStartTimeUs= */
    0, durationUs);
}
Also used : StatsDataSource(com.google.android.exoplayer2.upstream.StatsDataSource)

Aggregations

StatsDataSource (com.google.android.exoplayer2.upstream.StatsDataSource)7 LoadErrorInfo (com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy.LoadErrorInfo)2 LoadErrorAction (com.google.android.exoplayer2.upstream.Loader.LoadErrorAction)2 DataSourceInputStream (com.google.android.exoplayer2.upstream.DataSourceInputStream)1 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)1 InvalidResponseCodeException (com.google.android.exoplayer2.upstream.HttpDataSource.InvalidResponseCodeException)1