From 87d2f33e550f9e59fc6f528be06bd26eedbcb261 Mon Sep 17 00:00:00 2001 From: TobiGr Date: Sun, 23 May 2021 11:53:28 +0200 Subject: [PATCH] Add support for PeerTube HLS streams --- app/build.gradle | 2 +- .../java/org/schabi/newpipe/player/Player.java | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c6a420f07..e4fad9b9f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -183,7 +183,7 @@ dependencies { /** NewPipe libraries **/ // You can use a local version by uncommenting a few lines in settings.gradle implementation 'com.github.TeamNewPipe:nanojson:1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751' - implementation 'com.github.TeamNewPipe:NewPipeExtractor:3a3ade20f48cf37526eb970a7df56ee2405125fc' + implementation 'com.github.TeamNewPipe:NewPipeExtractor:636e27333b5dbd9bc3c54ef3a4c21a87e97253ee' /** Checkstyle **/ checkstyle "com.puppycrawl.tools:checkstyle:${checkstyleVersion}" 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 467202137..44d10df37 100644 --- a/app/src/main/java/org/schabi/newpipe/player/Player.java +++ b/app/src/main/java/org/schabi/newpipe/player/Player.java @@ -91,6 +91,7 @@ import org.schabi.newpipe.databinding.PlayerPopupCloseOverlayBinding; import org.schabi.newpipe.extractor.MediaFormat; import org.schabi.newpipe.extractor.stream.StreamInfo; import org.schabi.newpipe.extractor.stream.StreamSegment; +import org.schabi.newpipe.extractor.stream.StreamType; import org.schabi.newpipe.extractor.stream.VideoStream; import org.schabi.newpipe.fragments.OnScrollBelowItemsListener; import org.schabi.newpipe.fragments.detail.VideoDetailFragment; @@ -1632,9 +1633,22 @@ public final class Player implements if (exoPlayerIsNull()) { return; } + // Use duration of currentItem for non-live streams, + // because HLS streams are fragmented + // and thus the whole duration is not available to the player + // TODO: revert #6307 when introducing proper HLS support + final int duration; + if (currentItem != null + && currentItem.getStreamType() != StreamType.AUDIO_LIVE_STREAM + && currentItem.getStreamType() != StreamType.LIVE_STREAM) { + // convert seconds to milliseconds + duration = (int) (currentItem.getDuration() * 1000); + } else { + duration = (int) simpleExoPlayer.getDuration(); + } onUpdateProgress( Math.max((int) simpleExoPlayer.getCurrentPosition(), 0), - (int) simpleExoPlayer.getDuration(), + duration, simpleExoPlayer.getBufferedPercentage() ); }