From c6ead351c0cbeaaf02a0a33c43ad4a2fc53907d4 Mon Sep 17 00:00:00 2001 From: litetex <40789489+litetex@users.noreply.github.com> Date: Thu, 26 Aug 2021 17:16:51 +0200 Subject: [PATCH] Set ``KeyProgressIncrement`` manually * Set ``KeyProgressIncrement`` manually to the value of the seek duration in the settings so that it works when using the DPad * consolidated code inside a new method to avoid duplication --- .../org/schabi/newpipe/player/Player.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 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 83c567cb6..4a9f4fc72 100644 --- a/app/src/main/java/org/schabi/newpipe/player/Player.java +++ b/app/src/main/java/org/schabi/newpipe/player/Player.java @@ -1572,8 +1572,7 @@ public final class Player implements } if (duration != binding.playbackSeekBar.getMax()) { - binding.playbackEndTime.setText(getTimeString(duration)); - binding.playbackSeekBar.setMax(duration); + setVideoDurationToControls(duration); } if (currentState != STATE_PAUSED) { if (currentState != STATE_PAUSED_SEEK) { @@ -2073,8 +2072,8 @@ public final class Player implements Log.d(TAG, "onPrepared() called with: playWhenReady = [" + playWhenReady + "]"); } - binding.playbackSeekBar.setMax((int) simpleExoPlayer.getDuration()); - binding.playbackEndTime.setText(getTimeString((int) simpleExoPlayer.getDuration())); + setVideoDurationToControls((int) simpleExoPlayer.getDuration()); + binding.playbackSpeed.setText(formatSpeed(getPlaybackSpeed())); if (playWhenReady) { @@ -2716,6 +2715,20 @@ public final class Player implements simpleExoPlayer.seekToDefaultPosition(); } } + + /** + * Sets the video duration time into all control components (e.g. seekbar). + * @param duration + */ + private void setVideoDurationToControls(final int duration) { + binding.playbackEndTime.setText(getTimeString(duration)); + + binding.playbackSeekBar.setMax(duration); + // This is important for Android TVs otherwise it would apply the default from + // setMax/Min methods which is (max - min) / 20 + binding.playbackSeekBar.setKeyProgressIncrement( + PlayerHelper.retrieveSeekDurationFromPreferences(this)); + } //endregion