From c91763d4714449b5d99ccec378309d08063bc23b Mon Sep 17 00:00:00 2001 From: Benoit Dion Date: Mon, 23 Sep 2019 16:20:06 -0400 Subject: [PATCH] Clear progress messages on STATE_IDLE and STATE_BUFFERING The progress message handler will duplicate recursions of the `onProgressMessage` handler on change of player state from any state to STATE_READY with `playWhenReady` is true (when video is not paused). This clears the messages on STATE_IDLE and STATE_BUFFERING to break the recursion. --- .../brentvatne/exoplayer/ReactExoplayerView.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 a1fd402a82..4802a5a435 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -625,10 +625,12 @@ public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { case Player.STATE_IDLE: text += "idle"; eventEmitter.idle(); + clearProgressMessageHandler(); break; case Player.STATE_BUFFERING: text += "buffering"; onBuffering(true); + clearProgressMessageHandler(); break; case Player.STATE_READY: text += "ready"; @@ -636,7 +638,7 @@ public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { onBuffering(false); startProgressHandler(); videoLoaded(); - //Setting the visibility for the playerControlView + // Setting the visibility for the playerControlView if (playerControlView != null) { playerControlView.show(); } @@ -657,6 +659,15 @@ private void startProgressHandler() { progressHandler.sendEmptyMessage(SHOW_PROGRESS); } + /* + The progress message handler will duplicate recursions of the onProgressMessage handler + on change of player state from any state to STATE_READY with playWhenReady is true (when + the video is not paused). This clears all existing messages. + */ + private void clearProgressMessageHandler() { + progressHandler.removeMessages(SHOW_PROGRESS); + } + private void videoLoaded() { if (loadVideoStarted) { loadVideoStarted = false;