From 010c607e40cc08314cd623b716c9ca10d263762d Mon Sep 17 00:00:00 2001 From: litetex <40789489+litetex@users.noreply.github.com> Date: Mon, 8 Nov 2021 19:41:13 +0100 Subject: [PATCH 1/2] Prevent automatic replay after returning from background See also https://github.com/TeamNewPipe/NewPipe/pull/7195#issuecomment-962624380 --- .../main/java/org/schabi/newpipe/player/Player.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/Player.java b/app/src/main/java/org/schabi/newpipe/player/Player.java index b2708e075..4310ccad7 100644 --- a/app/src/main/java/org/schabi/newpipe/player/Player.java +++ b/app/src/main/java/org/schabi/newpipe/player/Player.java @@ -857,9 +857,15 @@ public final class Player implements final int queuePos = playQueue.getIndex(); final long windowPos = simpleExoPlayer.getCurrentPosition(); + final long duration = simpleExoPlayer.getDuration(); - if (windowPos > 0 && windowPos <= simpleExoPlayer.getDuration()) { - setRecovery(queuePos, windowPos); + if (windowPos > 0 + // Sometimes (e.g. when the playback ended) the windowPos is a few milliseconds + // higher than the duration. Due to this a little buffer (100ms) was introduced. + // See also https://github.com/TeamNewPipe/NewPipe/pull/7195#issuecomment-962624380 + && windowPos <= duration + 100 + ) { + setRecovery(queuePos, Math.min(windowPos, duration)); } } From 316db0e4c626986f19565dded5f2d4f8d85bffbe Mon Sep 17 00:00:00 2001 From: litetex <40789489+litetex@users.noreply.github.com> Date: Mon, 15 Nov 2021 19:56:14 +0100 Subject: [PATCH 2/2] setRecovery: Remove checks and use Math.min/max --- .../main/java/org/schabi/newpipe/player/Player.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/Player.java b/app/src/main/java/org/schabi/newpipe/player/Player.java index 4310ccad7..d448de5a4 100644 --- a/app/src/main/java/org/schabi/newpipe/player/Player.java +++ b/app/src/main/java/org/schabi/newpipe/player/Player.java @@ -859,14 +859,8 @@ public final class Player implements final long windowPos = simpleExoPlayer.getCurrentPosition(); final long duration = simpleExoPlayer.getDuration(); - if (windowPos > 0 - // Sometimes (e.g. when the playback ended) the windowPos is a few milliseconds - // higher than the duration. Due to this a little buffer (100ms) was introduced. - // See also https://github.com/TeamNewPipe/NewPipe/pull/7195#issuecomment-962624380 - && windowPos <= duration + 100 - ) { - setRecovery(queuePos, Math.min(windowPos, duration)); - } + // No checks due to https://github.com/TeamNewPipe/NewPipe/pull/7195#issuecomment-962624380 + setRecovery(queuePos, Math.max(0, Math.min(windowPos, duration))); } private void setRecovery(final int queuePos, final long windowPos) {