feat(player): Add support for editing input.conf (#1165)

This commit is contained in:
Abdallah 2023-10-22 19:58:54 +01:00 committed by GitHub
parent 63e95d9cbc
commit 418137c74e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 1 deletions

View file

@ -20,6 +20,7 @@ object AdvancedPlayerSettingsScreen : SearchableSettings {
val playerPreferences = remember { Injekt.get<PlayerPreferences>() } val playerPreferences = remember { Injekt.get<PlayerPreferences>() }
val context = LocalContext.current val context = LocalContext.current
val mpvConf = playerPreferences.mpvConf() val mpvConf = playerPreferences.mpvConf()
val mpvInput = playerPreferences.mpvInput()
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
return listOf( 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( Preference.PreferenceItem.ListPreference(
title = context.getString(R.string.pref_debanding_title), title = context.getString(R.string.pref_debanding_title),
pref = playerPreferences.deband(), pref = playerPreferences.deband(),

View file

@ -407,6 +407,8 @@ class PlayerActivity : BaseActivity() {
private fun setupPlayerMPV() { private fun setupPlayerMPV() {
val mpvConfFile = File("${applicationContext.filesDir.path}/mpv.conf") val mpvConfFile = File("${applicationContext.filesDir.path}/mpv.conf")
playerPreferences.mpvConf().get().let { mpvConfFile.writeText(it) } 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" val logLevel = if (viewModel.networkPreferences.verboseLogging().get()) "info" else "warn"
player.initialize(applicationContext.filesDir.path, logLevel) player.initialize(applicationContext.filesDir.path, logLevel)
@ -422,6 +424,8 @@ class PlayerActivity : BaseActivity() {
3 -> MPVLib.setOptionString("vf", "format=yuv420p") 3 -> MPVLib.setOptionString("vf", "format=yuv420p")
} }
MPVLib.setOptionString("input-default-bindings", "yes")
MPVLib.addLogObserver(playerObserver) MPVLib.addLogObserver(playerObserver)
player.addObserver(playerObserver) player.addObserver(playerObserver)
} }
@ -1042,11 +1046,33 @@ class PlayerActivity : BaseActivity() {
return true 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) 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") @Suppress("UNUSED_PARAMETER")
fun openTracksSheet(view: View) { fun openTracksSheet(view: View) {
val qualityTracks = currentVideoList?.map { Track("", it.quality) }?.toTypedArray()?.takeUnless { it.isEmpty() } val qualityTracks = currentVideoList?.map { Track("", it.quality) }?.toTypedArray()?.takeUnless { it.isEmpty() }

View file

@ -31,6 +31,8 @@ class PlayerPreferences(
fun mpvConf() = preferenceStore.getString("pref_mpv_conf", "") 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 defaultPlayerOrientationType() = preferenceStore.getInt("pref_default_player_orientation_type_key", 10)
fun adjustOrientationVideoDimensions() = preferenceStore.getBoolean("pref_adjust_orientation_video_dimensions", true) fun adjustOrientationVideoDimensions() = preferenceStore.getBoolean("pref_adjust_orientation_video_dimensions", true)

View file

@ -128,6 +128,7 @@
<string name="pref_remember_volume">Remember and switch to the last used volume</string> <string name="pref_remember_volume">Remember and switch to the last used volume</string>
<!-- Needs better English --> <!-- Needs better English -->
<string name="pref_mpv_conf">Edit MPV configuration file for further player settings</string> <string name="pref_mpv_conf">Edit MPV configuration file for further player settings</string>
<string name="pref_mpv_input">Edit MPV input file for keyboard mapping configuration</string>
<string name="pref_category_external_player">External player</string> <string name="pref_category_external_player">External player</string>
<string name="pref_always_use_external_player">Always use external player</string> <string name="pref_always_use_external_player">Always use external player</string>
<string name="pref_external_player_preference">External player preference</string> <string name="pref_external_player_preference">External player preference</string>