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 intro skip for media controls #1108

Merged
merged 3 commits into from
Aug 20, 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 @@ -248,6 +248,7 @@ object SettingsPlayerScreen : SearchableSettings {
Preference.PreferenceItem.SwitchPreference(
pref = mediaChapterSeek,
title = stringResource(R.string.pref_media_control_chapter_seeking),
subtitle = stringResource(R.string.pref_media_control_chapter_seeking_summary),
),
Preference.PreferenceItem.InfoPreference(
title = stringResource(R.string.pref_category_player_aniskip_info),
Expand Down
32 changes: 32 additions & 0 deletions app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ class PlayerActivity : BaseActivity() {
if (playerPreferences.mediaChapterSeek().get()) {
if (player.loadChapters().isNotEmpty()) {
MPVLib.command(arrayOf("add", "chapter", "-1"))
skipAnimation(getString(R.string.go_to_previous_chapter), isForward = false)
}
} else {
changeEpisode(viewModel.getAdjacentEpisodeId(previous = true))
Expand All @@ -497,6 +498,10 @@ class PlayerActivity : BaseActivity() {
if (playerPreferences.mediaChapterSeek().get()) {
if (player.loadChapters().isNotEmpty()) {
MPVLib.command(arrayOf("add", "chapter", "1"))
skipAnimation(getString(R.string.go_to_next_chapter), isForward = true)
} else {
MPVLib.command(arrayOf("seek", viewModel.getAnimeSkipIntroLength().toString(), "relative+exact"))
skipAnimation(getString(R.string.go_to_after_opening), isForward = true)
}
} else {
changeEpisode(viewModel.getAdjacentEpisodeId(previous = false))
Expand Down Expand Up @@ -920,6 +925,33 @@ class PlayerActivity : BaseActivity() {
MPVLib.command(arrayOf("seek", time.toString(), "relative+exact"))
}

// Taken from util/AniSkipApi.kt
private fun skipAnimation(skipText: String, isForward: Boolean) {
binding.secondsView.binding.doubleTapSeconds.text = skipText

binding.secondsView.updateLayoutParams<ConstraintLayout.LayoutParams> {
rightToRight = if (isForward) ConstraintLayout.LayoutParams.PARENT_ID else ConstraintLayout.LayoutParams.UNSET
leftToLeft = if (isForward) ConstraintLayout.LayoutParams.UNSET else ConstraintLayout.LayoutParams.PARENT_ID
}
binding.secondsView.visibility = View.VISIBLE
binding.secondsView.isForward = isForward

val bindingBg = if (isForward) binding.ffwdBg else binding.rewBg

bindingBg.visibility = View.VISIBLE
bindingBg.animate().alpha(0.15f).setDuration(100).withEndAction {
binding.secondsView.animate().alpha(1f).setDuration(500).withEndAction {
binding.secondsView.animate().alpha(0f).setDuration(500).withEndAction {
bindingBg.animate().alpha(0f).setDuration(100).withEndAction {
bindingBg.visibility = View.GONE
binding.secondsView.visibility = View.GONE
binding.secondsView.alpha = 1f
}
}
}
}.start()
}

// Gesture Functions -- Start --

internal fun initSeek() {
Expand Down
6 changes: 5 additions & 1 deletion i18n/src/main/res/values/strings-aniyomi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@
<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_media_control_chapter_seeking">Seek chapters with media controls</string>
<string name="pref_media_control_chapter_seeking_summary">When enabled, using next will invoke the skip intro button if no chapters are found</string>
<string name="go_to_next_chapter">Next chapter</string>
<string name="go_to_previous_chapter">Previous chapter</string>
<string name="go_to_after_opening">Skipped opening</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