From 52e89c1d1cea4226ec25c0708ecd0dea75794108 Mon Sep 17 00:00:00 2001 From: Stypox Date: Wed, 9 Sep 2020 20:41:30 +0200 Subject: [PATCH] Prevent seeking out of video duration in player --- .../java/org/schabi/newpipe/player/BasePlayer.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java index a26ec6ccb..5a60095ae 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java @@ -1242,7 +1242,15 @@ public abstract class BasePlayer implements Log.d(TAG, "seekBy() called with: position = [" + positionMillis + "]"); } if (simpleExoPlayer != null) { - simpleExoPlayer.seekTo(positionMillis); + // prevent invalid positions when fast-forwarding/-rewinding + long normalizedPositionMillis = positionMillis; + if (normalizedPositionMillis < 0) { + normalizedPositionMillis = 0; + } else if (normalizedPositionMillis > simpleExoPlayer.getDuration()) { + normalizedPositionMillis = simpleExoPlayer.getDuration(); + } + + simpleExoPlayer.seekTo(normalizedPositionMillis); } }