From dd3a4006896ef8b01733bf1ba00597c023240e9c Mon Sep 17 00:00:00 2001 From: Olivier Bouillet <62574056+freeboub@users.noreply.github.com> Date: Fri, 29 Mar 2024 20:59:58 +0100 Subject: [PATCH] Chore/fix strange management of resume (#3629) * fix(android): rename startPlayback to resumePlayback and fix implementation I cannot understand why this implementation has been done. I guess this is to workaround some issue... now resume only resume playback and don't start a new playback during bufffering... * chore: simplify duplicated code --- .../exoplayer/ReactExoplayerView.java | 26 +++++-------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index 41eb06e8..007a39e4 100644 --- a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -357,8 +357,7 @@ public class ReactExoplayerView extends FrameLayout implements @Override public void onHostDestroy() { - stopPlayback(); - themedReactContext.removeLifecycleEventListener(this); + cleanUpResources(); } public void cleanUpResources() { @@ -998,26 +997,13 @@ public class ReactExoplayerView extends FrameLayout implements } } - private void startPlayback() { + private void resumePlayback() { if (player != null) { - switch (player.getPlaybackState()) { - case Player.STATE_IDLE: - case Player.STATE_ENDED: - initializePlayer(); - break; - case Player.STATE_BUFFERING: - case Player.STATE_READY: - if (!player.getPlayWhenReady()) { - setPlayWhenReady(true); - } - break; - default: - break; + if (!player.getPlayWhenReady()) { + setPlayWhenReady(true); } - } else { - initializePlayer(); + setKeepScreenOn(preventsDisplaySleepDuringVideoPlayback); } - setKeepScreenOn(preventsDisplaySleepDuringVideoPlayback); } private void pausePlayback() { @@ -1850,7 +1836,7 @@ public class ReactExoplayerView extends FrameLayout implements isPaused = paused; if (player != null) { if (!paused) { - startPlayback(); + resumePlayback(); } else { pausePlayback(); }