-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VEX-4579: Network loss handling (#5)
Add support for customizing back buffer duration and handle network errors gracefully to prevent releasing the player when network is lost.
- Loading branch information
1 parent
f6cce0d
commit 8087310
Showing
6 changed files
with
87 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...oplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerLoadErrorHandlingPolicy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.brentvatne.exoplayer; | ||
|
||
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.LoadErrorHandlingPolicy.LoadErrorInfo; | ||
import com.google.android.exoplayer2.C; | ||
|
||
public final class ReactExoplayerLoadErrorHandlingPolicy extends DefaultLoadErrorHandlingPolicy { | ||
private int minLoadRetryCount = Integer.MAX_VALUE; | ||
|
||
public ReactExoplayerLoadErrorHandlingPolicy(int minLoadRetryCount) { | ||
super(minLoadRetryCount); | ||
this.minLoadRetryCount = minLoadRetryCount; | ||
} | ||
|
||
@Override | ||
public long getRetryDelayMsFor(LoadErrorInfo loadErrorInfo) { | ||
if (loadErrorInfo.exception instanceof HttpDataSourceException) { | ||
// 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 | ||
} | ||
} | ||
|
||
@Override | ||
public int getMinimumLoadableRetryCount(int dataType) { | ||
return Integer.MAX_VALUE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters