feat(player): Add option for chapter seeking using media controls (#1107)

This commit is contained in:
Secozzi 2023-08-13 22:11:49 +02:00 committed by GitHub
parent bcda386126
commit d04ae72f35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 3 deletions

View file

@ -194,6 +194,7 @@ object SettingsPlayerScreen : SearchableSettings {
val defaultSkipIntroLength by playerPreferences.defaultIntroLength().stateIn(scope).collectAsState()
val skipLengthPreference = playerPreferences.skipLengthPreference()
val playerSmoothSeek = playerPreferences.playerSmoothSeek()
val mediaChapterSeek = playerPreferences.mediaChapterSeek()
var showDialog by rememberSaveable { mutableStateOf(false) }
if (showDialog) {
@ -244,6 +245,10 @@ object SettingsPlayerScreen : SearchableSettings {
title = stringResource(R.string.pref_player_smooth_seek),
subtitle = stringResource(R.string.pref_player_smooth_seek_summary),
),
Preference.PreferenceItem.SwitchPreference(
pref = mediaChapterSeek,
title = stringResource(R.string.pref_media_control_chapter_seeking),
),
Preference.PreferenceItem.InfoPreference(
title = stringResource(R.string.pref_category_player_aniskip_info),
),

View file

@ -484,11 +484,23 @@ class PlayerActivity : BaseActivity() {
}
override fun onSkipToPrevious() {
changeEpisode(viewModel.getAdjacentEpisodeId(previous = true))
if (playerPreferences.mediaChapterSeek().get()) {
if (player.loadChapters().isNotEmpty()) {
MPVLib.command(arrayOf("add", "chapter", "-1"))
}
} else {
changeEpisode(viewModel.getAdjacentEpisodeId(previous = true))
}
}
override fun onSkipToNext() {
changeEpisode(viewModel.getAdjacentEpisodeId(previous = false))
if (playerPreferences.mediaChapterSeek().get()) {
if (player.loadChapters().isNotEmpty()) {
MPVLib.command(arrayOf("add", "chapter", "1"))
}
} else {
changeEpisode(viewModel.getAdjacentEpisodeId(previous = false))
}
}
},
)

View file

@ -43,6 +43,8 @@ class PlayerPreferences(
fun playerSmoothSeek() = preferenceStore.getBoolean("pref_player_smooth_seek", false)
fun mediaChapterSeek() = preferenceStore.getBoolean("pref_media_control_chapter_seeking", false)
fun playerViewMode() = preferenceStore.getInt("pref_player_view_mode", AspectState.FIT.index)
fun playerFullscreen() = preferenceStore.getBoolean("player_fullscreen", true)

View file

@ -63,7 +63,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:layout_marginTop="10dp"
android:layout_marginTop="16dp"
android:textColor="?attr/colorOnPrimarySurface"
android:textSize="14sp"
android:textStyle="bold"

View file

@ -106,6 +106,7 @@
<string name="pref_skip_5" translatable="false">5s</string>
<string name="pref_skip_3" translatable="false">3s</string>
<string name="pref_skip_disable">Disable</string>
<string name="pref_media_control_chapter_seeking">Use media controls for chapter seeking</string>
<string name="pref_player_smooth_seek">Enable precise seeking</string>
<string name="pref_player_smooth_seek_summary">When enabled, seeking will not focus on keyframes, leading to slower but precise seeking</string>
<string name="pref_player_fullscreen">Show content in display cutout</string>