From cd74c3836b5c728931924e0f1644b64637779da5 Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Fri, 18 Nov 2022 18:11:28 +0000 Subject: [PATCH] Implement proper handling of OTF videos. --- .../libretube/ui/fragments/PlayerFragment.kt | 15 ++++++++++----- .../java/com/github/libretube/util/DashHelper.kt | 5 +++++ 2 files changed, 15 insertions(+), 5 deletions(-) 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 b2c577392..bfcc3d5ea 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 @@ -1193,13 +1193,18 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions { if (!PreferenceHelper.getBoolean(PreferenceKeys.USE_HLS_OVER_DASH, false) && streams.videoStreams.orEmpty().isNotEmpty() ) { - val manifest = DashHelper.createManifest(streams) + val uri = let { + streams.dash?.toUri() - // encode to base64 - val encoded = Base64.encodeToString(manifest.toByteArray(), Base64.DEFAULT) - val mediaItem = "data:application/dash+xml;charset=utf-8;base64,$encoded" + val manifest = DashHelper.createManifest(streams) - this.setMediaSource(mediaItem.toUri(), MimeTypes.APPLICATION_MPD) + // encode to base64 + val encoded = Base64.encodeToString(manifest.toByteArray(), Base64.DEFAULT) + + "data:application/dash+xml;charset=utf-8;base64,$encoded".toUri() + } + + this.setMediaSource(uri, MimeTypes.APPLICATION_MPD) } else if (streams.hls != null) { setMediaSource(streams.hls.toUri(), MimeTypes.APPLICATION_M3U8) } else { diff --git a/app/src/main/java/com/github/libretube/util/DashHelper.kt b/app/src/main/java/com/github/libretube/util/DashHelper.kt index 8acadf5a4..52e7ea7a1 100644 --- a/app/src/main/java/com/github/libretube/util/DashHelper.kt +++ b/app/src/main/java/com/github/libretube/util/DashHelper.kt @@ -45,6 +45,11 @@ object DashHelper { continue } + // ignore streams which might be OTF + if (stream.indexEnd!! <= 0) { + continue + } + val adapSetInfo = adapSetInfos.find { it.mimeType == stream.mimeType } if (adapSetInfo != null) { adapSetInfo.formats.add(stream)