From 8782755cd6bbb99dbbfb2751fddf2125fdad84b1 Mon Sep 17 00:00:00 2001 From: olivier bouillet Date: Wed, 27 Apr 2022 21:26:37 +0200 Subject: [PATCH 1/3] fix(android, exoplayer): ensure playback progress is reported even if paused --- .../exoplayer/ReactExoplayerView.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) 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 b8c9a555..d617ca5e 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -165,21 +165,30 @@ class ReactExoplayerView extends FrameLayout implements private final AudioManager audioManager; private final AudioBecomingNoisyReceiver audioBecomingNoisyReceiver; + // store last progress event values to avoid sending unnecessary messages + private long lastPos = -1; + private long lastBufferDuration = -1; + private long lastDuration = -1; + private final Handler progressHandler = new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case SHOW_PROGRESS: - if (player != null - && player.getPlaybackState() == Player.STATE_READY - && player.getPlayWhenReady() - ) { - long pos = player.getCurrentPosition(); - long bufferedDuration = player.getBufferedPercentage() * player.getDuration() / 100; + long pos = player.getCurrentPosition(); + long bufferedDuration = player.getBufferedPercentage() * player.getDuration() / 100; + long duration = player.getDuration(); + + if (lastPos != pos + || lastBufferDuration != bufferedDuration + || lastDuration != duration) { + lastPos = pos; + lastBufferDuration = bufferedDuration; + lastDuration = duration; eventEmitter.progressChanged(pos, bufferedDuration, player.getDuration(), getPositionInFirstPeriodMsForCurrentWindow(pos)); - msg = obtainMessage(SHOW_PROGRESS); - sendMessageDelayed(msg, Math.round(mProgressUpdateInterval)); } + msg = obtainMessage(SHOW_PROGRESS); + sendMessageDelayed(msg, Math.round(mProgressUpdateInterval)); break; } } From a019f258267af890f897211bb5f2f0a921aacbe8 Mon Sep 17 00:00:00 2001 From: olivier bouillet Date: Wed, 27 Apr 2022 21:32:26 +0200 Subject: [PATCH 2/3] chore: upgrade changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index edb1f2c6..a544345a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Version 6.0.0-alpha1 +- Fix Exoplayer progress not reported when paused [#2664](https://github.com/react-native-video/react-native-video/pull/2664) - Add Google's maven repository to avoid build error [#2552](https://github.com/react-native-video/react-native-video/pull/2552) - Fix iOS 15.4 HLS playback race condition [#2633](https://github.com/react-native-video/react-native-video/pull/2633) - Add fullscreen support on Android [#2073](https://github.com/react-native-video/react-native-video/pull/2073) From e33e2a9cb5abbaf132bcf832469821dc1dca9665 Mon Sep 17 00:00:00 2001 From: olivier bouillet Date: Wed, 15 Jun 2022 22:04:57 +0200 Subject: [PATCH 3/3] chore(exoplayer): ensure no NPE happen --- .../exoplayer/ReactExoplayerView.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) 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 f960dd63..69e0c516 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -215,20 +215,22 @@ class ReactExoplayerView extends FrameLayout implements public void handleMessage(Message msg) { switch (msg.what) { case SHOW_PROGRESS: - long pos = player.getCurrentPosition(); - long bufferedDuration = player.getBufferedPercentage() * player.getDuration() / 100; - long duration = player.getDuration(); + if (player != null) { + long pos = player.getCurrentPosition(); + long bufferedDuration = player.getBufferedPercentage() * player.getDuration() / 100; + long duration = player.getDuration(); - if (lastPos != pos - || lastBufferDuration != bufferedDuration - || lastDuration != duration) { - lastPos = pos; - lastBufferDuration = bufferedDuration; - lastDuration = duration; - eventEmitter.progressChanged(pos, bufferedDuration, player.getDuration(), getPositionInFirstPeriodMsForCurrentWindow(pos)); + if (lastPos != pos + || lastBufferDuration != bufferedDuration + || lastDuration != duration) { + lastPos = pos; + lastBufferDuration = bufferedDuration; + lastDuration = duration; + eventEmitter.progressChanged(pos, bufferedDuration, player.getDuration(), getPositionInFirstPeriodMsForCurrentWindow(pos)); + } + msg = obtainMessage(SHOW_PROGRESS); + sendMessageDelayed(msg, Math.round(mProgressUpdateInterval)); } - msg = obtainMessage(SHOW_PROGRESS); - sendMessageDelayed(msg, Math.round(mProgressUpdateInterval)); break; } }