Skip to content

Commit

Permalink
ETPAND-9981: Don't retry 403 ExoPlayer HttpDataSourceExceptions (#64)
Browse files Browse the repository at this point in the history
* Catch 403 & 401 errors when downloading segments
  • Loading branch information
armands-malejevs authored May 12, 2023
1 parent 4acb828 commit 9251587
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import java.io.IOException;
import com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy;
import com.google.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException;
import com.google.android.exoplayer2.upstream.HttpDataSource.InvalidResponseCodeException;
import com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy.LoadErrorInfo;
import com.google.android.exoplayer2.C;

import android.util.Log;

public final class ReactExoplayerLoadErrorHandlingPolicy extends DefaultLoadErrorHandlingPolicy {
private int minLoadRetryCount = Integer.MAX_VALUE;

Expand All @@ -16,6 +19,18 @@ public ReactExoplayerLoadErrorHandlingPolicy(int minLoadRetryCount) {

@Override
public long getRetryDelayMsFor(LoadErrorInfo loadErrorInfo) {

if (loadErrorInfo.exception instanceof InvalidResponseCodeException) {
if (((InvalidResponseCodeException)loadErrorInfo.exception).responseCode == 403) {
Log.w("RNV", "Request returned 403 - stopping retry!");
return C.TIME_UNSET;
}
if (((InvalidResponseCodeException)loadErrorInfo.exception).responseCode == 401) {
Log.w("RNV", "Request returned 401 - stopping retry!");
return C.TIME_UNSET;
}
}

if (
loadErrorInfo.exception instanceof HttpDataSourceException &&
(loadErrorInfo.exception.getMessage() == "Unable to connect" || loadErrorInfo.exception.getMessage() == "Software caused connection abort")
Expand Down

0 comments on commit 9251587

Please sign in to comment.