mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-30 08:18:00 +01:00
loop videos after ending if desired
This commit is contained in:
parent
677e68332c
commit
7d758178d5
1 changed files with 23 additions and 4 deletions
|
@ -242,7 +242,7 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val wasEnded = videoEnded()
|
val wasEnded = didVideoEnd()
|
||||||
if (wasEnded) {
|
if (wasEnded) {
|
||||||
setPosition(0)
|
setPosition(0)
|
||||||
}
|
}
|
||||||
|
@ -259,7 +259,7 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
||||||
}
|
}
|
||||||
|
|
||||||
mIsPlaying = false
|
mIsPlaying = false
|
||||||
if (!videoEnded()) {
|
if (!didVideoEnd()) {
|
||||||
mExoPlayer?.playWhenReady = false
|
mExoPlayer?.playWhenReady = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,17 +288,29 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun videoCompleted() {
|
private fun videoCompleted() {
|
||||||
|
if (mExoPlayer == null) {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun videoEnded(): Boolean {
|
clearLastVideoSavedProgress()
|
||||||
|
mCurrTime = (mExoPlayer!!.duration / 1000).toInt()
|
||||||
|
if (config.loopVideos) {
|
||||||
|
playVideo()
|
||||||
|
} else {
|
||||||
|
video_seekbar.progress = video_seekbar.max
|
||||||
|
video_curr_time.text = mDuration.getFormattedDuration()
|
||||||
|
pauseVideo()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun didVideoEnd(): Boolean {
|
||||||
val currentPos = mExoPlayer?.currentPosition ?: 0
|
val currentPos = mExoPlayer?.currentPosition ?: 0
|
||||||
val duration = mExoPlayer?.duration ?: 0
|
val duration = mExoPlayer?.duration ?: 0
|
||||||
return currentPos != 0L && currentPos >= duration
|
return currentPos != 0L && currentPos >= duration
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun saveVideoProgress() {
|
private fun saveVideoProgress() {
|
||||||
if (!videoEnded()) {
|
if (!didVideoEnd()) {
|
||||||
config.apply {
|
config.apply {
|
||||||
lastVideoPosition = mExoPlayer!!.currentPosition.toInt() / 1000
|
lastVideoPosition = mExoPlayer!!.currentPosition.toInt() / 1000
|
||||||
lastVideoPath = mUri.toString()
|
lastVideoPath = mUri.toString()
|
||||||
|
@ -306,6 +318,13 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun clearLastVideoSavedProgress() {
|
||||||
|
config.apply {
|
||||||
|
lastVideoPosition = 0
|
||||||
|
lastVideoPath = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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
|
||||||
|
|
Loading…
Reference in a new issue