Skip to content

Commit

Permalink
feat(player): Add option for chapter seeking using media controls (#1107
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Secozzi authored Aug 13, 2023
1 parent bcda386 commit d04ae72
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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),
),
Expand Down
16 changes: 14 additions & 2 deletions app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/player_controls.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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 @@ -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>
Expand Down

0 comments on commit d04ae72

Please sign in to comment.