apply the double tap skipping on the separate window player too

This commit is contained in:
tibbi 2020-02-17 22:45:50 +01:00
parent f175c71621
commit 641df80b21
3 changed files with 28 additions and 7 deletions

View File

@ -163,6 +163,7 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
video_duration.setOnClickListener { skip(true) }
video_toggle_play_pause.setOnClickListener { togglePlayPause() }
video_surface_frame.setOnClickListener { toggleFullscreen() }
video_surface_frame.controller.settings.swallowDoubleTaps = true
video_next_file.beVisibleIf(intent.getBooleanExtra(SHOW_NEXT_ITEM, false))
video_next_file.setOnClickListener { handleNextFile() }
@ -170,8 +171,24 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
video_prev_file.beVisibleIf(intent.getBooleanExtra(SHOW_PREV_ITEM, false))
video_prev_file.setOnClickListener { handlePrevFile() }
val gestureDetector = GestureDetector(this, object : GestureDetector.SimpleOnGestureListener() {
override fun onDoubleTap(e: MotionEvent?): Boolean {
val instantWidth = mScreenWidth / 7
val clickedX = e?.rawX ?: 0f
when {
clickedX <= instantWidth -> doSkip(DOUBLE_TAP_SKIP_VIDEO_MS, false)
clickedX >= mScreenWidth - instantWidth -> doSkip(DOUBLE_TAP_SKIP_VIDEO_MS, true)
else -> togglePlayPause()
}
return true
}
})
video_surface_frame.setOnTouchListener { view, event ->
handleEvent(event)
gestureDetector.onTouchEvent(event)
false
}
@ -475,11 +492,15 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
return
}
val curr = mExoPlayer!!.currentPosition
val twoPercents = Math.max((mExoPlayer!!.duration / 50).toInt(), MIN_SKIP_LENGTH)
val newProgress = if (forward) curr + twoPercents else curr - twoPercents
doSkip(twoPercents, forward)
}
private fun doSkip(millis: Int, forward: Boolean) {
val curr = mExoPlayer!!.currentPosition
val newProgress = if (forward) curr + millis else curr - millis
val roundProgress = Math.round(newProgress / 1000f)
val limitedProgress = Math.max(Math.min(mExoPlayer!!.duration.toInt(), roundProgress), 0)
val limitedProgress = Math.max(Math.min(mExoPlayer!!.duration.toInt() / 1000, roundProgress), 0)
setPosition(limitedProgress)
if (!mIsPlaying) {
togglePlayPause()

View File

@ -39,7 +39,6 @@ import java.io.FileInputStream
class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, SeekBar.OnSeekBarChangeListener {
private val PROGRESS = "progress"
private val DOUBLE_TAP_SKIP_MS = 10000
private var mIsFullscreen = false
private var mWasFragmentInit = false
@ -137,8 +136,8 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
val instantWidth = viewWidth / 7
val clickedX = e?.rawX ?: 0f
when {
clickedX <= instantWidth -> doSkip(DOUBLE_TAP_SKIP_MS, false)
clickedX >= viewWidth - instantWidth -> doSkip(DOUBLE_TAP_SKIP_MS, true)
clickedX <= instantWidth -> doSkip(DOUBLE_TAP_SKIP_VIDEO_MS, false)
clickedX >= viewWidth - instantWidth -> doSkip(DOUBLE_TAP_SKIP_VIDEO_MS, true)
else -> togglePlayPause()
}
@ -544,7 +543,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
val curr = mExoPlayer!!.currentPosition
val newProgress = if (forward) curr + millis else curr - millis
val roundProgress = Math.round(newProgress / 1000f)
val limitedProgress = Math.max(Math.min(mExoPlayer!!.duration.toInt(), roundProgress), 0)
val limitedProgress = Math.max(Math.min(mExoPlayer!!.duration.toInt() / 1000, roundProgress), 0)
setPosition(limitedProgress)
if (!mIsPlaying) {
togglePlayPause()

View File

@ -118,6 +118,7 @@ const val MONTH_MILLISECONDS = MONTH_SECONDS * 1000L
const val MIN_SKIP_LENGTH = 2000
const val HIDE_SYSTEM_UI_DELAY = 500L
const val MAX_PRINT_SIDE_SIZE = 4096
const val DOUBLE_TAP_SKIP_VIDEO_MS = 10000
const val DIRECTORY = "directory"
const val MEDIUM = "medium"