From 3fcd580491e254d476ed94cef0ae82553ef77708 Mon Sep 17 00:00:00 2001 From: Tom <25043847+Douile@users.noreply.github.com> Date: Thu, 8 Apr 2021 08:41:41 +0000 Subject: [PATCH] Add queue time (#6023) * Add queue time --- .../org/schabi/newpipe/player/Player.java | 33 +++++++++++++++++++ app/src/main/res/layout/player.xml | 11 +++++++ 2 files changed, 44 insertions(+) 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 37a061edc..55d191703 100644 --- a/app/src/main/java/org/schabi/newpipe/player/Player.java +++ b/app/src/main/java/org/schabi/newpipe/player/Player.java @@ -1596,6 +1596,10 @@ public final class Player implements segmentAdapter.selectSegmentAt(getNearestStreamSegmentPosition(currentProgress)); } + if (isQueueVisible) { + updateQueueTime(currentProgress); + } + final boolean showThumbnail = prefs.getBoolean( context.getString(R.string.show_thumbnail_key), true); // setMetadata only updates the metadata when any of the metadata keys are null @@ -2964,6 +2968,7 @@ public final class Player implements buildQueue(); binding.itemsListHeaderTitle.setVisibility(View.GONE); + binding.itemsListHeaderDuration.setVisibility(View.VISIBLE); binding.shuffleButton.setVisibility(View.VISIBLE); binding.repeatButton.setVisibility(View.VISIBLE); @@ -2973,6 +2978,8 @@ public final class Player implements AnimationType.SLIDE_AND_ALPHA); binding.itemsList.scrollToPosition(playQueue.getIndex()); + + updateQueueTime((int) simpleExoPlayer.getCurrentPosition()); } private void buildQueue() { @@ -3195,6 +3202,32 @@ public final class Player implements buildPlaybackSpeedMenu(); binding.playbackSpeed.setVisibility(View.VISIBLE); } + + private void updateQueueTime(final int currentTime) { + final int currentStream = playQueue.getIndex(); + int before = 0; + int after = 0; + + final List streams = playQueue.getStreams(); + final int nStreams = streams.size(); + + for (int i = 0; i < nStreams; i++) { + if (i < currentStream) { + before += streams.get(i).getDuration(); + } else { + after += streams.get(i).getDuration(); + } + } + + before *= 1000; + after *= 1000; + + binding.itemsListHeaderDuration.setText( + String.format("%s/%s", + getTimeString(currentTime + before), + getTimeString(before + after) + )); + } //endregion diff --git a/app/src/main/res/layout/player.xml b/app/src/main/res/layout/player.xml index 35f4765d1..3614d1fbb 100644 --- a/app/src/main/res/layout/player.xml +++ b/app/src/main/res/layout/player.xml @@ -559,6 +559,17 @@ android:tint="?attr/colorAccent" app:srcCompat="@drawable/ic_shuffle" tools:ignore="ContentDescription,RtlHardcoded" /> + +