From 418137c74e891c03a14b0cc6d54638679b9cb583 Mon Sep 17 00:00:00 2001 From: Abdallah <54363735+abdallahmehiz@users.noreply.github.com> Date: Sun, 22 Oct 2023 19:58:54 +0100 Subject: [PATCH] feat(player): Add support for editing input.conf (#1165) --- .../screen/AdvancedPlayerSettingsScreen.kt | 11 ++++++++ .../tachiyomi/ui/player/PlayerActivity.kt | 28 ++++++++++++++++++- .../ui/player/settings/PlayerPreferences.kt | 2 ++ i18n/src/main/res/values/strings-aniyomi.xml | 1 + 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/AdvancedPlayerSettingsScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/AdvancedPlayerSettingsScreen.kt index 5601c14039..2ddce07532 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/AdvancedPlayerSettingsScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/AdvancedPlayerSettingsScreen.kt @@ -20,6 +20,7 @@ object AdvancedPlayerSettingsScreen : SearchableSettings { val playerPreferences = remember { Injekt.get() } val context = LocalContext.current val mpvConf = playerPreferences.mpvConf() + val mpvInput = playerPreferences.mpvInput() val scope = rememberCoroutineScope() return listOf( @@ -34,6 +35,16 @@ object AdvancedPlayerSettingsScreen : SearchableSettings { ), ), + Preference.PreferenceItem.MultiLineEditTextPreference( + pref = mpvInput, + title = context.getString(R.string.pref_mpv_input), + subtitle = mpvInput.asState(scope).value + .lines().take(2) + .joinToString( + separator = "\n", + postfix = if (mpvInput.asState(scope).value.lines().size > 2) "\n..." else "", + ), + ), Preference.PreferenceItem.ListPreference( title = context.getString(R.string.pref_debanding_title), pref = playerPreferences.deband(), 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 5f04804a84..c52128096d 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 @@ -407,6 +407,8 @@ class PlayerActivity : BaseActivity() { private fun setupPlayerMPV() { val mpvConfFile = File("${applicationContext.filesDir.path}/mpv.conf") playerPreferences.mpvConf().get().let { mpvConfFile.writeText(it) } + val mpvInputFile = File("${applicationContext.filesDir.path}/input.conf") + playerPreferences.mpvInput().get().let { mpvInputFile.writeText(it) } val logLevel = if (viewModel.networkPreferences.verboseLogging().get()) "info" else "warn" player.initialize(applicationContext.filesDir.path, logLevel) @@ -422,6 +424,8 @@ class PlayerActivity : BaseActivity() { 3 -> MPVLib.setOptionString("vf", "format=yuv420p") } + MPVLib.setOptionString("input-default-bindings", "yes") + MPVLib.addLogObserver(playerObserver) player.addObserver(playerObserver) } @@ -1042,11 +1046,33 @@ class PlayerActivity : BaseActivity() { return true } */ - else -> {} + KeyEvent.KEYCODE_DPAD_RIGHT -> { + doubleTapSeek(playerPreferences.skipLengthPreference().get()) + return true + } + KeyEvent.KEYCODE_DPAD_LEFT -> { + doubleTapSeek(-playerPreferences.skipLengthPreference().get()) + return true + } + KeyEvent.KEYCODE_SPACE -> { + doubleTapPlayPause() + return true + } + // add other keycodes as needed + else -> { + if (player.onKey(event!!)) return true + } } return super.onKeyDown(keyCode, event) } + // Removing this causes mpv to repeat the last repeated input + // that's not specified in onKeyDown indefinitely for some reason + override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean { + if (player.onKey(event!!)) return true + return super.onKeyUp(keyCode, event) + } + @Suppress("UNUSED_PARAMETER") fun openTracksSheet(view: View) { val qualityTracks = currentVideoList?.map { Track("", it.quality) }?.toTypedArray()?.takeUnless { it.isEmpty() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/player/settings/PlayerPreferences.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/player/settings/PlayerPreferences.kt index 7ad3cee3e8..434abc5d04 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/player/settings/PlayerPreferences.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/player/settings/PlayerPreferences.kt @@ -31,6 +31,8 @@ class PlayerPreferences( fun mpvConf() = preferenceStore.getString("pref_mpv_conf", "") + fun mpvInput() = preferenceStore.getString("pref_mpv_input", "") + fun defaultPlayerOrientationType() = preferenceStore.getInt("pref_default_player_orientation_type_key", 10) fun adjustOrientationVideoDimensions() = preferenceStore.getBoolean("pref_adjust_orientation_video_dimensions", true) diff --git a/i18n/src/main/res/values/strings-aniyomi.xml b/i18n/src/main/res/values/strings-aniyomi.xml index 67898bcd64..9144e02b7d 100644 --- a/i18n/src/main/res/values/strings-aniyomi.xml +++ b/i18n/src/main/res/values/strings-aniyomi.xml @@ -128,6 +128,7 @@ Remember and switch to the last used volume Edit MPV configuration file for further player settings + Edit MPV input file for keyboard mapping configuration External player Always use external player External player preference