From df4df4fccc7f568c5f5708784ab118beaab79971 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 16 Jul 2023 17:33:37 +0200 Subject: [PATCH] Ignore unknown audio track types Co-authored-by: AudricV <74829229+AudricV@users.noreply.github.com> --- .../github/libretube/helpers/DashHelper.kt | 26 +++++++++---------- .../libretube/ui/fragments/PlayerFragment.kt | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) 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 de382facf..6b75cb29f 100644 --- a/app/src/main/java/com/github/libretube/helpers/DashHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/DashHelper.kt @@ -115,14 +115,18 @@ object DashHelper { adapSetElement.setAttribute("lang", adapSet.audioLocale) } - val roleElement = doc.createElement("Role") - roleElement.setAttribute("schemeIdUri", "urn:mpeg:dash:role:2011") - roleElement.setAttribute( - "value", - getRoleValueFromAudioTrackType(adapSet.audioTrackType) - ) - - adapSetElement.appendChild(roleElement) + // Only add the Role element if there is a track type set + // This allows distinction between formats marked as original on YouTube and + // formats without track type info set + if (adapSet.audioTrackType != null) { + val roleElement = doc.createElement("Role") + roleElement.setAttribute("schemeIdUri", "urn:mpeg:dash:role:2011") + roleElement.setAttribute( + "value", + getRoleValueFromAudioTrackType(adapSet.audioTrackType) + ) + adapSetElement.appendChild(roleElement) + } val isVideo = adapSet.mimeType.contains("video") @@ -198,11 +202,7 @@ object DashHelper { return segmentBase } - private fun getRoleValueFromAudioTrackType(audioTrackType: String?): String { - if (audioTrackType == null) { - return "main" - } - + private fun getRoleValueFromAudioTrackType(audioTrackType: String): String { return when (audioTrackType.lowercase()) { "descriptive" -> "description" "dubbed" -> "dub" 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 836c8691f..0287db45e 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 @@ -1429,7 +1429,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { } .show(childFragmentManager) } - + override fun onAudioStreamClicked() { val context = requireContext() val audioLanguagesAndRoleFlags = PlayerHelper.getAudioLanguagesAndRoleFlagsFromTrackGroups(