From 10c9978bc8c6a171774d775060e01dc6d96ef0d4 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Fri, 30 Jun 2023 15:56:31 +0200 Subject: [PATCH] Fix immediate transition to next video when starting player --- .../com/github/libretube/api/obj/Streams.kt | 4 ++-- .../github/libretube/helpers/DashHelper.kt | 19 ++++++++++++++++--- .../github/libretube/helpers/ProxyHelper.kt | 8 ++++++-- .../libretube/services/OnlinePlayerService.kt | 9 ++++++--- .../libretube/ui/fragments/PlayerFragment.kt | 18 +++++++++++++----- 5 files changed, 43 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/github/libretube/api/obj/Streams.kt b/app/src/main/java/com/github/libretube/api/obj/Streams.kt index 8f7adf444..e0c6639eb 100644 --- a/app/src/main/java/com/github/libretube/api/obj/Streams.kt +++ b/app/src/main/java/com/github/libretube/api/obj/Streams.kt @@ -63,8 +63,8 @@ data class Streams( path = Paths.get(""), url = subtitles.find { it.code == subCode - }?.url?.let { ProxyHelper.unwrapUrl(it) }, - ), + }?.url?.let { ProxyHelper.unwrapUrl(it) } + ) ) } diff --git a/app/src/main/java/com/github/libretube/helpers/DashHelper.kt b/app/src/main/java/com/github/libretube/helpers/DashHelper.kt index 7c1c81ea5..2d8853755 100644 --- a/app/src/main/java/com/github/libretube/helpers/DashHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/DashHelper.kt @@ -23,7 +23,12 @@ object DashHelper { val formats: MutableList = mutableListOf() ) - fun createManifest(streams: Streams, supportsHdr: Boolean, audioOnly: Boolean = false, rewriteUrls: Boolean): String { + fun createManifest( + streams: Streams, + supportsHdr: Boolean, + audioOnly: Boolean = false, + rewriteUrls: Boolean + ): String { val builder = builderFactory.newDocumentBuilder() val doc = builder.newDocument() @@ -137,7 +142,11 @@ object DashHelper { return writer.toString() } - private fun createAudioRepresentation(doc: Document, stream: PipedStream, rewriteUrls: Boolean): Element { + private fun createAudioRepresentation( + doc: Document, + stream: PipedStream, + rewriteUrls: Boolean + ): Element { val representation = doc.createElement("Representation") representation.setAttribute("bandwidth", stream.bitrate.toString()) representation.setAttribute("codecs", stream.codec!!) @@ -167,7 +176,11 @@ object DashHelper { return representation } - private fun createVideoRepresentation(doc: Document, stream: PipedStream, rewriteUrls: Boolean): Element { + private fun createVideoRepresentation( + doc: Document, + stream: PipedStream, + rewriteUrls: Boolean + ): Element { val representation = doc.createElement("Representation") representation.setAttribute("codecs", stream.codec!!) representation.setAttribute("bandwidth", stream.bitrate.toString()) diff --git a/app/src/main/java/com/github/libretube/helpers/ProxyHelper.kt b/app/src/main/java/com/github/libretube/helpers/ProxyHelper.kt index 2d9e0a27f..b48b01de4 100644 --- a/app/src/main/java/com/github/libretube/helpers/ProxyHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/ProxyHelper.kt @@ -48,9 +48,13 @@ object ProxyHelper { else -> true } - fun unwrapImageUrl(url: String): String = if ( + fun unwrapImageUrl(url: String) = if ( !PreferenceHelper.getBoolean(PreferenceKeys.DISABLE_VIDEO_IMAGE_PROXY, false) - ) url else unwrapUrl(url) + ) { + url + } else { + unwrapUrl(url) + } /** * Convert a proxied Piped url to a YouTube url that's not proxied diff --git a/app/src/main/java/com/github/libretube/services/OnlinePlayerService.kt b/app/src/main/java/com/github/libretube/services/OnlinePlayerService.kt index 22168dad7..cf5c345a4 100644 --- a/app/src/main/java/com/github/libretube/services/OnlinePlayerService.kt +++ b/app/src/main/java/com/github/libretube/services/OnlinePlayerService.kt @@ -25,7 +25,6 @@ import com.github.libretube.api.obj.Streams import com.github.libretube.constants.BACKGROUND_CHANNEL_ID import com.github.libretube.constants.IntentData import com.github.libretube.constants.PLAYER_NOTIFICATION_ID -import com.github.libretube.constants.PreferenceKeys import com.github.libretube.db.DatabaseHolder.Database import com.github.libretube.db.obj.WatchPosition import com.github.libretube.enums.SbSkipOptions @@ -35,7 +34,6 @@ import com.github.libretube.extensions.toID import com.github.libretube.helpers.PlayerHelper import com.github.libretube.helpers.PlayerHelper.checkForSegments import com.github.libretube.helpers.PlayerHelper.loadPlaybackParams -import com.github.libretube.helpers.PreferenceHelper import com.github.libretube.helpers.ProxyHelper import com.github.libretube.obj.PlayerNotificationData import com.github.libretube.parcelable.PlayerData @@ -303,7 +301,12 @@ class OnlinePlayerService : LifecycleService() { val (uri, mimeType) = if (streams.audioStreams.isNotEmpty()) { val disableProxy = ProxyHelper.shouldDisableProxy(streams.videoStreams.first().url!!) - PlayerHelper.createDashSource(streams, this, true, disableProxy) to MimeTypes.APPLICATION_MPD + PlayerHelper.createDashSource( + streams, + this, + true, + disableProxy + ) to MimeTypes.APPLICATION_MPD } else { ProxyHelper.unwrapStreamUrl(streams.hls.orEmpty()).toUri() to MimeTypes.APPLICATION_M3U8 } diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt index 52b976996..101e8899f 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt @@ -155,7 +155,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { */ private var sId: Int = 0 private var eId: Int = 0 - private var transitioning = false + private var transitioning = true /** * for the player @@ -1305,10 +1305,18 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { false ) && streams.videoStreams.isNotEmpty() -> { // only use the dash manifest generated by YT if either it's a livestream or no other source is available - val dashUri = if (streams.livestream && streams.dash != null) ProxyHelper.unwrapStreamUrl(streams.dash!!).toUri() else { - val shouldDisableProxy = ProxyHelper.shouldDisableProxy(streams.videoStreams.first().url!!) - PlayerHelper.createDashSource(streams, requireContext(), disableProxy = shouldDisableProxy) - } + val dashUri = + if (streams.livestream && streams.dash != null) ProxyHelper.unwrapStreamUrl( + streams.dash!! + ).toUri() else { + val shouldDisableProxy = + ProxyHelper.shouldDisableProxy(streams.videoStreams.first().url!!) + PlayerHelper.createDashSource( + streams, + requireContext(), + disableProxy = shouldDisableProxy + ) + } dashUri to MimeTypes.APPLICATION_MPD }