mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-23 04:57:59 +01:00
remove some jerkyness during video playback fastforward/rewind
This commit is contained in:
parent
ed4d870261
commit
80d3bf4cea
1 changed files with 17 additions and 7 deletions
|
@ -32,6 +32,8 @@ import kotlinx.android.synthetic.main.activity_video_player.*
|
||||||
import kotlinx.android.synthetic.main.bottom_video_time_holder.*
|
import kotlinx.android.synthetic.main.bottom_video_time_holder.*
|
||||||
|
|
||||||
open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListener, TextureView.SurfaceTextureListener {
|
open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListener, TextureView.SurfaceTextureListener {
|
||||||
|
private val PLAY_WHEN_READY_DRAG_DELAY = 100L
|
||||||
|
|
||||||
private var mIsFullscreen = false
|
private var mIsFullscreen = false
|
||||||
private var mIsPlaying = false
|
private var mIsPlaying = false
|
||||||
private var mWasVideoStarted = false
|
private var mWasVideoStarted = false
|
||||||
|
@ -45,6 +47,7 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
||||||
private var mUri: Uri? = null
|
private var mUri: Uri? = null
|
||||||
private var mExoPlayer: SimpleExoPlayer? = null
|
private var mExoPlayer: SimpleExoPlayer? = null
|
||||||
private var mTimerHandler = Handler()
|
private var mTimerHandler = Handler()
|
||||||
|
private var mPlayWhenReadyHandler = Handler()
|
||||||
|
|
||||||
private var mTouchDownX = 0f
|
private var mTouchDownX = 0f
|
||||||
private var mTouchDownY = 0f
|
private var mTouchDownY = 0f
|
||||||
|
@ -97,7 +100,12 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
if (!isChangingConfigurations) {
|
if (!isChangingConfigurations) {
|
||||||
cleanup()
|
pauseVideo()
|
||||||
|
video_curr_time.text = 0.getFormattedDuration()
|
||||||
|
releaseExoPlayer()
|
||||||
|
video_seekbar.progress = 0
|
||||||
|
mTimerHandler.removeCallbacksAndMessages(null)
|
||||||
|
mPlayWhenReadyHandler.removeCallbacksAndMessages(null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -485,6 +493,7 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
||||||
newProgress = Math.max(Math.min(mExoPlayer!!.duration.toFloat(), newProgress), 0f)
|
newProgress = Math.max(Math.min(mExoPlayer!!.duration.toFloat(), newProgress), 0f)
|
||||||
val newSeconds = (newProgress / 1000).toInt()
|
val newSeconds = (newProgress / 1000).toInt()
|
||||||
setPosition(newSeconds)
|
setPosition(newSeconds)
|
||||||
|
resetPlayWhenReady()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MotionEvent.ACTION_UP -> {
|
MotionEvent.ACTION_UP -> {
|
||||||
|
@ -511,12 +520,12 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun cleanup() {
|
private fun resetPlayWhenReady() {
|
||||||
pauseVideo()
|
mExoPlayer?.playWhenReady = false
|
||||||
video_curr_time.text = 0.getFormattedDuration()
|
mPlayWhenReadyHandler.removeCallbacksAndMessages(null)
|
||||||
releaseExoPlayer()
|
mPlayWhenReadyHandler.postDelayed({
|
||||||
video_seekbar.progress = 0
|
mExoPlayer?.playWhenReady = true
|
||||||
mTimerHandler.removeCallbacksAndMessages(null)
|
}, PLAY_WHEN_READY_DRAG_DELAY)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun releaseExoPlayer() {
|
private fun releaseExoPlayer() {
|
||||||
|
@ -530,6 +539,7 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
||||||
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
|
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
|
||||||
if (mExoPlayer != null && fromUser) {
|
if (mExoPlayer != null && fromUser) {
|
||||||
setPosition(progress)
|
setPosition(progress)
|
||||||
|
resetPlayWhenReady()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue