From 59e5018c2d9b58de333f7bdab5c3f66f4c14f4dd Mon Sep 17 00:00:00 2001 From: "Yevhen Babiichuk (DustDFG)" Date: Wed, 28 Jan 2026 20:25:47 +0200 Subject: [PATCH 1/2] player/helper/PlayerHelper#getTimeString replace ints with longs Duration data in the player code incosnistently typed. Half code uses ints and half uses longs. Recieve longs in this function to allow both halfs of player code just use the function without nasty long to int downcasting warnings/errors in code --- .../org/schabi/newpipe/player/helper/PlayerHelper.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java index 0f9579352..11d39a5c5 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java @@ -87,11 +87,11 @@ public final class PlayerHelper { } @NonNull - public static String getTimeString(final int milliSeconds) { - final int seconds = (milliSeconds % 60000) / 1000; - final int minutes = (milliSeconds % 3600000) / 60000; - final int hours = (milliSeconds % 86400000) / 3600000; - final int days = (milliSeconds % (86400000 * 7)) / 86400000; + public static String getTimeString(final long milliSeconds) { + final long seconds = (milliSeconds % 60000) / 1000; + final long minutes = (milliSeconds % 3600000) / 60000; + final long hours = (milliSeconds % 86400000) / 3600000; + final long days = (milliSeconds % (86400000 * 7)) / 86400000; final Formatters formatters = FORMATTERS_PROVIDER.formatters(); if (days > 0) { From 3a0a3a42afc91b31d0ee0184a85caaf658ebc0e2 Mon Sep 17 00:00:00 2001 From: "Yevhen Babiichuk (DustDFG)" Date: Wed, 28 Jan 2026 20:14:36 +0200 Subject: [PATCH 2/2] Misc loop/stream based player refactors --- .../newpipe/player/helper/PlayerHelper.java | 9 ++++--- .../player/playqueue/SinglePlayQueue.java | 8 ++----- .../newpipe/player/ui/MainPlayerUi.java | 24 +++++++------------ 3 files changed, 14 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java index 11d39a5c5..25844f799 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java @@ -49,12 +49,12 @@ import java.text.DecimalFormatSymbols; import java.text.NumberFormat; import java.util.ArrayList; import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Objects; import java.util.Set; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; public final class PlayerHelper { private static final FormattersProvider FORMATTERS_PROVIDER = new FormattersProvider(); @@ -174,10 +174,9 @@ public final class PlayerHelper { @Nullable public static PlayQueue autoQueueOf(@NonNull final StreamInfo info, @NonNull final List existingItems) { - final Set urls = new HashSet<>(existingItems.size()); - for (final PlayQueueItem item : existingItems) { - urls.add(item.getUrl()); - } + final Set urls = existingItems.stream() + .map(PlayQueueItem::getUrl) + .collect(Collectors.toUnmodifiableSet()); final List relatedItems = info.getRelatedItems(); if (Utils.isNullOrEmpty(relatedItems)) { diff --git a/app/src/main/java/org/schabi/newpipe/player/playqueue/SinglePlayQueue.java b/app/src/main/java/org/schabi/newpipe/player/playqueue/SinglePlayQueue.java index f13d7924d..a072369d6 100644 --- a/app/src/main/java/org/schabi/newpipe/player/playqueue/SinglePlayQueue.java +++ b/app/src/main/java/org/schabi/newpipe/player/playqueue/SinglePlayQueue.java @@ -5,8 +5,8 @@ import androidx.annotation.NonNull; import org.schabi.newpipe.extractor.stream.StreamInfo; import org.schabi.newpipe.extractor.stream.StreamInfoItem; -import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; public final class SinglePlayQueue extends PlayQueue { public SinglePlayQueue(final StreamInfoItem item) { @@ -29,11 +29,7 @@ public final class SinglePlayQueue extends PlayQueue { } private static List playQueueItemsOf(@NonNull final List items) { - final List playQueueItems = new ArrayList<>(items.size()); - for (final StreamInfoItem item : items) { - playQueueItems.add(new PlayQueueItem(item)); - } - return playQueueItems; + return items.stream().map(PlayQueueItem::new).collect(Collectors.toList()); } @Override diff --git a/app/src/main/java/org/schabi/newpipe/player/ui/MainPlayerUi.java b/app/src/main/java/org/schabi/newpipe/player/ui/MainPlayerUi.java index 868881782..4d85dc950 100644 --- a/app/src/main/java/org/schabi/newpipe/player/ui/MainPlayerUi.java +++ b/app/src/main/java/org/schabi/newpipe/player/ui/MainPlayerUi.java @@ -77,6 +77,7 @@ import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.Optional; +import java.util.stream.Collectors; public final class MainPlayerUi extends VideoPlayerUi implements View.OnLayoutChangeListener { private static final String TAG = MainPlayerUi.class.getSimpleName(); @@ -749,13 +750,13 @@ public final class MainPlayerUi extends VideoPlayerUi implements View.OnLayoutCh } private int getNearestStreamSegmentPosition(final long playbackPosition) { - int nearestPosition = 0; final List segments = player.getCurrentStreamInfo() .map(StreamInfo::getStreamSegments) .orElse(Collections.emptyList()); - for (int i = 0; i < segments.size(); i++) { - if (segments.get(i).getStartTimeSeconds() * 1000L > playbackPosition) { + int nearestPosition = 0; + for (final var segment : segments) { + if (segment.getStartTimeSeconds() * 1000L > playbackPosition) { break; } nearestPosition++; @@ -816,22 +817,13 @@ public final class MainPlayerUi extends VideoPlayerUi implements View.OnLayoutCh } 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(); - } - } + final long before = streams.subList(0, currentStream).stream() + .collect(Collectors.summingLong(PlayQueueItem::getDuration)) * 1000; - before *= 1000; - after *= 1000; + final long after = streams.subList(currentStream, streams.size()).stream() + .collect(Collectors.summingLong(PlayQueueItem::getDuration)) * 1000; binding.itemsListHeaderDuration.setText( String.format("%s/%s",