feat(player): Use doubleTapSeek for chapter seeking & show seekbar on seek (#1202)

Co-authored-by: jmir1 <jhmiramon@gmail.com>
This commit is contained in:
Secozzi 2023-11-09 18:00:43 +00:00 committed by GitHub
parent fd83a7e141
commit 8b1934fc36
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -645,8 +645,11 @@ class PlayerActivity : BaseActivity() {
override fun onSkipToPrevious() { override fun onSkipToPrevious() {
if (playerPreferences.mediaChapterSeek().get()) { if (playerPreferences.mediaChapterSeek().get()) {
if (player.loadChapters().isNotEmpty()) { if (player.loadChapters().isNotEmpty()) {
MPVLib.command(arrayOf("add", "chapter", "-1")) doubleTapSeek(
skipAnimation(getString(R.string.go_to_previous_chapter), isForward = false) -1,
videoChapterText = getString(R.string.go_to_previous_chapter),
chapterSeek = "-1",
)
} }
} else { } else {
changeEpisode(viewModel.getAdjacentEpisodeId(previous = true)) changeEpisode(viewModel.getAdjacentEpisodeId(previous = true))
@ -656,11 +659,13 @@ class PlayerActivity : BaseActivity() {
override fun onSkipToNext() { override fun onSkipToNext() {
if (playerPreferences.mediaChapterSeek().get()) { if (playerPreferences.mediaChapterSeek().get()) {
if (player.loadChapters().isNotEmpty()) { if (player.loadChapters().isNotEmpty()) {
MPVLib.command(arrayOf("add", "chapter", "1")) doubleTapSeek(
skipAnimation(getString(R.string.go_to_next_chapter), isForward = true) 1,
videoChapterText = getString(R.string.go_to_next_chapter),
chapterSeek = "1",
)
} else { } else {
MPVLib.command(arrayOf("seek", viewModel.getAnimeSkipIntroLength().toString(), "relative+exact")) doubleTapSeek(viewModel.getAnimeSkipIntroLength())
skipAnimation(getString(R.string.go_to_after_opening), isForward = true)
} }
} else { } else {
changeEpisode(viewModel.getAdjacentEpisodeId(previous = false)) changeEpisode(viewModel.getAdjacentEpisodeId(previous = false))
@ -1028,6 +1033,7 @@ class PlayerActivity : BaseActivity() {
event: MotionEvent? = null, event: MotionEvent? = null,
isDoubleTap: Boolean = true, isDoubleTap: Boolean = true,
videoChapterText: String? = null, videoChapterText: String? = null,
chapterSeek: String? = null,
) { ) {
if (SeekState.mode != SeekState.DOUBLE_TAP) { if (SeekState.mode != SeekState.DOUBLE_TAP) {
doubleTapBg = if (time < 0) binding.rewBg else binding.ffwdBg doubleTapBg = if (time < 0) binding.rewBg else binding.ffwdBg
@ -1082,7 +1088,7 @@ class PlayerActivity : BaseActivity() {
binding.secondsView.seconds += time binding.secondsView.seconds += time
} }
} }
if (videoChapterText == null) { if (videoChapterText == null || chapterSeek != null) {
playerControls.hideUiForSeek() playerControls.hideUiForSeek()
} }
binding.secondsView.start() binding.secondsView.start()
@ -1091,34 +1097,11 @@ class PlayerActivity : BaseActivity() {
ObjectAnimator.ofFloat(view, "alpha", 0f, 0.15f).setDuration(500).start() ObjectAnimator.ofFloat(view, "alpha", 0f, 0.15f).setDuration(500).start()
ObjectAnimator.ofFloat(view, "alpha", 0.15f, 0.15f, 0f).setDuration(1000).start() ObjectAnimator.ofFloat(view, "alpha", 0.15f, 0.15f, 0f).setDuration(1000).start()
if (chapterSeek == null) {
MPVLib.command(arrayOf("seek", time.toString(), "relative+exact")) MPVLib.command(arrayOf("seek", time.toString(), "relative+exact"))
} else {
MPVLib.command(arrayOf("add", "chapter", chapterSeek))
} }
// 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 -- // Gesture Functions -- Start --