From c51100d0b593cb86f0f5d70803ecae50654ea937 Mon Sep 17 00:00:00 2001 From: Secozzi <49240133+Secozzi@users.noreply.github.com> Date: Thu, 11 Jul 2024 12:54:55 +0000 Subject: [PATCH] feat(player): Set mpv's media-title property (#1672) --- .../tachiyomi/ui/player/PlayerActivity.kt | 21 +++++++++++++++++++ .../moko-resources/base/strings.xml | 1 + 2 files changed, 22 insertions(+) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerActivity.kt index 6d99cebe7..715ff6fbc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerActivity.kt @@ -112,6 +112,8 @@ import java.io.IOException import java.io.InputStream import java.io.OutputStream import kotlin.math.abs +import kotlin.math.ceil +import kotlin.math.floor import kotlin.math.roundToInt import `is`.xyz.mpv.MPVView.Chapter as VideoChapter @@ -1735,6 +1737,7 @@ class PlayerActivity : BaseActivity() { // at void is.xyz.mpv.MPVLib.event(int) (MPVLib.java:86) @SuppressLint("SourceLockedOrientationActivity") internal suspend fun fileLoaded() { + setMpvMediaTitle() val localLangName = LocaleHelper.getSimpleLocaleDisplayName() clearTracks() player.loadTracks() @@ -1827,6 +1830,24 @@ class PlayerActivity : BaseActivity() { } } + private fun setMpvMediaTitle() { + val anime = viewModel.currentAnime ?: return + val episode = viewModel.currentEpisode ?: return + + val epNumber = episode.episode_number.let { number -> + if (ceil(number) == floor(number)) number.toInt() else number + }.toString().padStart(2, '0') + + val title = stringResource( + MR.strings.mpv_media_title, + anime.title, + epNumber, + episode.name, + ) + + MPVLib.setPropertyString("force-media-title", title) + } + private var aniskipStamps: List = emptyList() private fun updateChapters(stamps: List? = null, duration: Int? = null) { diff --git a/i18n/src/commonMain/moko-resources/base/strings.xml b/i18n/src/commonMain/moko-resources/base/strings.xml index 65d7ca309..349157981 100644 --- a/i18n/src/commonMain/moko-resources/base/strings.xml +++ b/i18n/src/commonMain/moko-resources/base/strings.xml @@ -903,6 +903,7 @@ Next chapter Previous chapter Skipped opening + %1$s - E%2$s - %3$s Enable precise seeking When enabled, seeking will not focus on keyframes, leading to slower but precise seeking Show content in display cutout