remember last video playback position if set so

This commit is contained in:
tibbi 2019-01-02 18:25:17 +01:00
parent 76c859a041
commit 677e68332c

View file

@ -77,6 +77,10 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
override fun onPause() { override fun onPause() {
super.onPause() super.onPause()
pauseVideo() pauseVideo()
if (config.rememberLastVideoPosition && mWasVideoStarted) {
saveVideoProgress()
}
} }
override fun onDestroy() { override fun onDestroy() {
@ -224,6 +228,11 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
video_seekbar.max = mDuration video_seekbar.max = mDuration
video_duration.text = mDuration.getFormattedDuration() video_duration.text = mDuration.getFormattedDuration()
setPosition(mCurrTime) setPosition(mCurrTime)
if (config.rememberLastVideoPosition) {
setLastVideoSavedPosition()
}
playVideo() playVideo()
} }
} }
@ -272,6 +281,12 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
video_curr_time.text = seconds.getFormattedDuration() video_curr_time.text = seconds.getFormattedDuration()
} }
private fun setLastVideoSavedPosition() {
if (config.lastVideoPath == mUri.toString() && config.lastVideoPosition > 0) {
setPosition(config.lastVideoPosition)
}
}
private fun videoCompleted() { private fun videoCompleted() {
} }
@ -282,6 +297,15 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
return currentPos != 0L && currentPos >= duration return currentPos != 0L && currentPos >= duration
} }
private fun saveVideoProgress() {
if (!videoEnded()) {
config.apply {
lastVideoPosition = mExoPlayer!!.currentPosition.toInt() / 1000
lastVideoPath = mUri.toString()
}
}
}
private fun setVideoSize() { private fun setVideoSize() {
val videoProportion = mVideoSize.x.toFloat() / mVideoSize.y.toFloat() val videoProportion = mVideoSize.x.toFloat() / mVideoSize.y.toFloat()
val display = windowManager.defaultDisplay val display = windowManager.defaultDisplay