Skip to content

Commit

Permalink
feat(player): Add support for editing input.conf (#1165)
Browse files Browse the repository at this point in the history
  • Loading branch information
abdallahmehiz authored Oct 22, 2023
1 parent 63e95d9 commit 418137c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ object AdvancedPlayerSettingsScreen : SearchableSettings {
val playerPreferences = remember { Injekt.get<PlayerPreferences>() }
val context = LocalContext.current
val mpvConf = playerPreferences.mpvConf()
val mpvInput = playerPreferences.mpvInput()
val scope = rememberCoroutineScope()

return listOf(
Expand All @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
Expand Down Expand Up @@ -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() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions i18n/src/main/res/values/strings-aniyomi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
<string name="pref_remember_volume">Remember and switch to the last used volume</string>
<!-- Needs better English -->
<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_always_use_external_player">Always use external player</string>
<string name="pref_external_player_preference">External player preference</string>
Expand Down

0 comments on commit 418137c

Please sign in to comment.