Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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