From bc81f2af98c174d8a984df561ea03c046e24d997 Mon Sep 17 00:00:00 2001 From: Hampton Maxwell Date: Sun, 10 Feb 2019 20:07:29 -0800 Subject: [PATCH] Merge pull request #1448 from sridhard/master Feature Implementation: Recovery from transient internet failures (rebased from commit 4424774ca3d1058773eb19f3ddb90d52dff99025) --- CHANGELOG.md | 1 + README.md | 13 +++++++++++++ Video.js | 1 + android-exoplayer/build.gradle | 2 +- .../exoplayer/ReactExoplayerView.java | 19 +++++++++++++++---- .../exoplayer/ReactExoplayerViewManager.java | 6 ++++++ 6 files changed, 37 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 280ada24fc..38cf892b66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ * Fix text not appearing in release builds of Android apps [#1373](https://github.com/react-native-community/react-native-video/pull/1373) * Update to ExoPlayer 2.9.3 [#1406](https://github.com/react-native-community/react-native-video/pull/1406) * Add video track selection & onBandwidthUpdate [#1199](https://github.com/react-native-community/react-native-video/pull/1199) +* Recovery from transient internet failures and props to configure the custom retry count [#1448](https://github.com/react-native-community/react-native-video/pull/1448) ### Version 4.2.0 * Don't initialize filters on iOS unless a filter is set. This was causing a startup performance regression [#1360](https://github.com/react-native-community/react-native-video/pull/1360) diff --git a/README.md b/README.md index a8a6b4c542..4546a4df72 100644 --- a/README.md +++ b/README.md @@ -269,6 +269,7 @@ var styles = StyleSheet.create({ * [id](#id) * [ignoreSilentSwitch](#ignoresilentswitch) * [maxBitRate](#maxbitrate) +* [minLoadRetryCount](#minLoadRetryCount) * [muted](#muted) * [paused](#paused) * [playInBackground](#playinbackground) @@ -475,6 +476,18 @@ maxBitRate={2000000} // 2 megabits Platforms: Android ExoPlayer, iOS +#### minLoadRetryCount +Sets the minimum number of times to retry loading data before failing and reporting an error to the application. Useful to recover from transient internet failures. + +Default: 3. Retry 3 times. + +Example: +``` +minLoadRetryCount={5} // retry 5 times +``` + +Platforms: Android ExoPlayer + #### muted Controls whether the audio is muted * **false (default)** - Don't mute audio diff --git a/Video.js b/Video.js index 78adea5e5d..3335c8c184 100644 --- a/Video.js +++ b/Video.js @@ -387,6 +387,7 @@ Video.propTypes = { // Opaque type returned by require('./video.mp4') PropTypes.number ]), + minLoadRetryCount: PropTypes.number, maxBitRate: PropTypes.number, resizeMode: PropTypes.string, poster: PropTypes.string, diff --git a/android-exoplayer/build.gradle b/android-exoplayer/build.gradle index 810686fd99..3308022fd5 100644 --- a/android-exoplayer/build.gradle +++ b/android-exoplayer/build.gradle @@ -35,4 +35,4 @@ dependencies { // ZL: CHANGED TO VERSION 3.14.0 implementation 'com.squareup.okhttp3:okhttp:3.14.0' -} +} \ No newline at end of file diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index d5dca1043c..452432ce2e 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -118,6 +118,7 @@ class ReactExoplayerView extends FrameLayout implements private boolean isBuffering; private float rate = 1f; private float audioVolume = 1f; + private int minLoadRetryCount = 3; private int maxBitRate = 0; private long seekTime = C.TIME_UNSET; @@ -404,12 +405,17 @@ private MediaSource buildMediaSource(Uri uri, String overrideExtension) { switch (type) { case C.TYPE_SS: return new SsMediaSource(uri, buildDataSourceFactory(false), - new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mainHandler, null); + new DefaultSsChunkSource.Factory(mediaDataSourceFactory), + minLoadRetryCount, SsMediaSource.DEFAULT_LIVE_PRESENTATION_DELAY_MS, + mainHandler, null); case C.TYPE_DASH: return new DashMediaSource(uri, buildDataSourceFactory(false), - new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mainHandler, null); + new DefaultDashChunkSource.Factory(mediaDataSourceFactory), + minLoadRetryCount, DashMediaSource.DEFAULT_LIVE_PRESENTATION_DELAY_MS, + mainHandler, null); case C.TYPE_HLS: - return new HlsMediaSource(uri, mediaDataSourceFactory, mainHandler, null); + return new HlsMediaSource(uri, mediaDataSourceFactory, + minLoadRetryCount, mainHandler, null); case C.TYPE_OTHER: return new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(), mainHandler, null); @@ -988,7 +994,7 @@ public void setSelectedTrack(int trackType, String type, Dynamic value) { TrackGroup group = groups.get(i); for (int j = 0; j < group.length; j++) { Format format = group.getFormat(j); - if (format.height == value.asInt()) { + if (format.height == height) { groupIndex = i; tracks[0] = j; break; @@ -1116,6 +1122,11 @@ public void setMaxBitRateModifier(int newMaxBitRate) { } } + public void setMinLoadRetryCountModifier(int newMinLoadRetryCount) { + minLoadRetryCount = newMinLoadRetryCount; + releasePlayer(); + initializePlayer(); + } public void setPlayInBackground(boolean playInBackground) { this.playInBackground = playInBackground; diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java index 7f3f37f5ec..e01329362b 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java @@ -53,6 +53,7 @@ public class ReactExoplayerViewManager extends ViewGroupManager