skip by 10s at clicking on the curr/max video durations too

This commit is contained in:
tibbi 2020-02-20 12:04:16 +01:00
parent 349dfd414a
commit b2da6f5080
3 changed files with 15 additions and 17 deletions

View File

@ -195,13 +195,13 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
video_brightness_controller.initialize(this, slide_info, true, video_player_holder, singleTap = { x, y -> video_brightness_controller.initialize(this, slide_info, true, video_player_holder, singleTap = { x, y ->
toggleFullscreen() toggleFullscreen()
}, doubleTap = {x, y -> }, doubleTap = {x, y ->
doSkip(DOUBLE_TAP_SKIP_VIDEO_MS, false) doSkip(false)
}) })
video_volume_controller.initialize(this, slide_info, false, video_player_holder, singleTap = { x, y -> video_volume_controller.initialize(this, slide_info, false, video_player_holder, singleTap = { x, y ->
toggleFullscreen() toggleFullscreen()
}, doubleTap = {x, y -> }, doubleTap = {x, y ->
doSkip(DOUBLE_TAP_SKIP_VIDEO_MS, true) doSkip(true)
}) })
} else { } else {
video_brightness_controller.beGone() video_brightness_controller.beGone()
@ -307,8 +307,8 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
private fun handleDoubleTap(x: Float) { private fun handleDoubleTap(x: Float) {
val instantWidth = mScreenWidth / 7 val instantWidth = mScreenWidth / 7
when { when {
x <= instantWidth -> doSkip(DOUBLE_TAP_SKIP_VIDEO_MS, false) x <= instantWidth -> doSkip(false)
x >= mScreenWidth - instantWidth -> doSkip(DOUBLE_TAP_SKIP_VIDEO_MS, true) x >= mScreenWidth - instantWidth -> doSkip(true)
else -> togglePlayPause() else -> togglePlayPause()
} }
} }
@ -501,13 +501,12 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
return return
} }
val twoPercents = Math.max((mExoPlayer!!.duration / 50).toInt(), MIN_SKIP_LENGTH) doSkip(forward)
doSkip(twoPercents, forward)
} }
private fun doSkip(millis: Int, forward: Boolean) { private fun doSkip(forward: Boolean) {
val curr = mExoPlayer!!.currentPosition val curr = mExoPlayer!!.currentPosition
val newProgress = if (forward) curr + millis else curr - millis val newProgress = if (forward) curr + FAST_FORWARD_VIDEO_MS else curr - FAST_FORWARD_VIDEO_MS
val roundProgress = Math.round(newProgress / 1000f) val roundProgress = Math.round(newProgress / 1000f)
val limitedProgress = Math.max(Math.min(mExoPlayer!!.duration.toInt() / 1000, roundProgress), 0) val limitedProgress = Math.max(Math.min(mExoPlayer!!.duration.toInt() / 1000, roundProgress), 0)
setPosition(limitedProgress) setPosition(limitedProgress)

View File

@ -207,7 +207,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
toggleFullscreen() toggleFullscreen()
} }
}, doubleTap = {x, y -> }, doubleTap = {x, y ->
doSkip(DOUBLE_TAP_SKIP_VIDEO_MS, false) doSkip(false)
}) })
mVolumeSideScroll.initialize(activity!!, slide_info, false, container, singleTap = { x, y -> mVolumeSideScroll.initialize(activity!!, slide_info, false, container, singleTap = { x, y ->
@ -217,7 +217,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
toggleFullscreen() toggleFullscreen()
} }
}, doubleTap = {x, y -> }, doubleTap = {x, y ->
doSkip(DOUBLE_TAP_SKIP_VIDEO_MS, true) doSkip(true)
}) })
video_surface.onGlobalLayout { video_surface.onGlobalLayout {
@ -431,8 +431,8 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
val viewWidth = mView.width val viewWidth = mView.width
val instantWidth = viewWidth / 7 val instantWidth = viewWidth / 7
when { when {
x <= instantWidth -> doSkip(DOUBLE_TAP_SKIP_VIDEO_MS, false) x <= instantWidth -> doSkip(false)
x >= viewWidth - instantWidth -> doSkip(DOUBLE_TAP_SKIP_VIDEO_MS, true) x >= viewWidth - instantWidth -> doSkip(true)
else -> togglePlayPause() else -> togglePlayPause()
} }
} }
@ -542,13 +542,12 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
} }
mPositionAtPause = 0L mPositionAtPause = 0L
val twoPercents = Math.max((mExoPlayer!!.duration / 50).toInt(), MIN_SKIP_LENGTH) doSkip(forward)
doSkip(twoPercents, forward)
} }
private fun doSkip(millis: Int, forward: Boolean) { private fun doSkip(forward: Boolean) {
val curr = mExoPlayer!!.currentPosition val curr = mExoPlayer!!.currentPosition
val newProgress = if (forward) curr + millis else curr - millis val newProgress = if (forward) curr + FAST_FORWARD_VIDEO_MS else curr - FAST_FORWARD_VIDEO_MS
val roundProgress = Math.round(newProgress / 1000f) val roundProgress = Math.round(newProgress / 1000f)
val limitedProgress = Math.max(Math.min(mExoPlayer!!.duration.toInt() / 1000, roundProgress), 0) val limitedProgress = Math.max(Math.min(mExoPlayer!!.duration.toInt() / 1000, roundProgress), 0)
setPosition(limitedProgress) setPosition(limitedProgress)

View File

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