2021-05-17 13:09:09 +03:00
|
|
|
package com.brentvatne.exoplayer;
|
|
|
|
|
2023-11-18 22:13:54 +09:00
|
|
|
import androidx.media3.common.C;
|
|
|
|
import androidx.media3.datasource.HttpDataSource.HttpDataSourceException;
|
|
|
|
import androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy;
|
2021-05-17 13:09:09 +03:00
|
|
|
|
|
|
|
public final class ReactExoplayerLoadErrorHandlingPolicy extends DefaultLoadErrorHandlingPolicy {
|
2023-11-18 22:13:54 +09:00
|
|
|
private final int minLoadRetryCount;
|
2021-05-17 13:09:09 +03:00
|
|
|
|
2023-11-18 22:13:54 +09:00
|
|
|
public ReactExoplayerLoadErrorHandlingPolicy(int minLoadRetryCount) {
|
|
|
|
super(minLoadRetryCount);
|
|
|
|
this.minLoadRetryCount = minLoadRetryCount;
|
|
|
|
}
|
2021-05-17 13:09:09 +03:00
|
|
|
|
2023-11-18 22:13:54 +09:00
|
|
|
@Override
|
|
|
|
public long getRetryDelayMsFor(LoadErrorInfo loadErrorInfo) {
|
|
|
|
String errorMessage = loadErrorInfo.exception.getMessage();
|
2023-10-12 10:36:43 +02:00
|
|
|
|
2023-11-18 22:13:54 +09:00
|
|
|
if (
|
|
|
|
loadErrorInfo.exception instanceof HttpDataSourceException &&
|
|
|
|
errorMessage != null && (errorMessage.equals("Unable to connect") || errorMessage.equals("Software caused connection abort"))
|
|
|
|
) {
|
|
|
|
// Capture the error we get when there is no network connectivity and keep retrying it
|
|
|
|
return 1000; // Retry every second
|
|
|
|
} else if(loadErrorInfo.errorCount < this.minLoadRetryCount) {
|
|
|
|
return Math.min((loadErrorInfo.errorCount - 1) * 1000, 5000); // Default timeout handling
|
|
|
|
} else {
|
|
|
|
return C.TIME_UNSET; // Done retrying and will return the error immediately
|
|
|
|
}
|
2021-05-17 13:09:09 +03:00
|
|
|
}
|
|
|
|
|
2023-11-18 22:13:54 +09:00
|
|
|
@Override
|
|
|
|
public int getMinimumLoadableRetryCount(int dataType) {
|
|
|
|
return Integer.MAX_VALUE;
|
|
|
|
}
|
2023-10-12 10:36:43 +02:00
|
|
|
}
|