Merge pull request #1728 from ForgottenUmbrella/seamless
Loop videos without gaps between playback
This commit is contained in:
commit
f933296a65
2 changed files with 26 additions and 16 deletions
|
@ -214,6 +214,9 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
||||||
mExoPlayer = ExoPlayerFactory.newSimpleInstance(applicationContext).apply {
|
mExoPlayer = ExoPlayerFactory.newSimpleInstance(applicationContext).apply {
|
||||||
seekParameters = SeekParameters.CLOSEST_SYNC
|
seekParameters = SeekParameters.CLOSEST_SYNC
|
||||||
audioStreamType = C.STREAM_TYPE_MUSIC
|
audioStreamType = C.STREAM_TYPE_MUSIC
|
||||||
|
if (config.loopVideos) {
|
||||||
|
repeatMode = Player.REPEAT_MODE_ONE
|
||||||
|
}
|
||||||
prepare(audioSource)
|
prepare(audioSource)
|
||||||
}
|
}
|
||||||
initExoPlayerListeners()
|
initExoPlayerListeners()
|
||||||
|
@ -231,7 +234,13 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
||||||
|
|
||||||
override fun onLoadingChanged(isLoading: Boolean) {}
|
override fun onLoadingChanged(isLoading: Boolean) {}
|
||||||
|
|
||||||
override fun onPositionDiscontinuity(reason: Int) {}
|
override fun onPositionDiscontinuity(reason: Int) {
|
||||||
|
// Reset progress views when video loops.
|
||||||
|
if (reason == Player.DISCONTINUITY_REASON_PERIOD_TRANSITION) {
|
||||||
|
video_seekbar.progress = 0
|
||||||
|
video_curr_time.text = 0.getFormattedDuration()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onRepeatModeChanged(repeatMode: Int) {}
|
override fun onRepeatModeChanged(repeatMode: Int) {}
|
||||||
|
|
||||||
|
@ -338,14 +347,10 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
||||||
|
|
||||||
clearLastVideoSavedProgress()
|
clearLastVideoSavedProgress()
|
||||||
mCurrTime = (mExoPlayer!!.duration / 1000).toInt()
|
mCurrTime = (mExoPlayer!!.duration / 1000).toInt()
|
||||||
if (config.loopVideos) {
|
|
||||||
resumeVideo()
|
|
||||||
} else {
|
|
||||||
video_seekbar.progress = video_seekbar.max
|
video_seekbar.progress = video_seekbar.max
|
||||||
video_curr_time.text = mDuration.getFormattedDuration()
|
video_curr_time.text = mDuration.getFormattedDuration()
|
||||||
pauseVideo()
|
pauseVideo()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun didVideoEnd(): Boolean {
|
private fun didVideoEnd(): Boolean {
|
||||||
val currentPos = mExoPlayer?.currentPosition ?: 0
|
val currentPos = mExoPlayer?.currentPosition ?: 0
|
||||||
|
|
|
@ -317,6 +317,9 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
|
|
||||||
mExoPlayer = ExoPlayerFactory.newSimpleInstance(context)
|
mExoPlayer = ExoPlayerFactory.newSimpleInstance(context)
|
||||||
mExoPlayer!!.seekParameters = SeekParameters.CLOSEST_SYNC
|
mExoPlayer!!.seekParameters = SeekParameters.CLOSEST_SYNC
|
||||||
|
if (mConfig.loopVideos) {
|
||||||
|
mExoPlayer?.repeatMode = Player.REPEAT_MODE_ONE
|
||||||
|
}
|
||||||
|
|
||||||
val isContentUri = mMedium.path.startsWith("content://")
|
val isContentUri = mMedium.path.startsWith("content://")
|
||||||
val uri = if (isContentUri) Uri.parse(mMedium.path) else Uri.fromFile(File(mMedium.path))
|
val uri = if (isContentUri) Uri.parse(mMedium.path) else Uri.fromFile(File(mMedium.path))
|
||||||
|
@ -350,7 +353,13 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
|
|
||||||
override fun onLoadingChanged(isLoading: Boolean) {}
|
override fun onLoadingChanged(isLoading: Boolean) {}
|
||||||
|
|
||||||
override fun onPositionDiscontinuity(reason: Int) {}
|
override fun onPositionDiscontinuity(reason: Int) {
|
||||||
|
// Reset progress views when video loops.
|
||||||
|
if (reason == Player.DISCONTINUITY_REASON_PERIOD_TRANSITION) {
|
||||||
|
mSeekBar.progress = 0
|
||||||
|
mCurrTimeView.text = 0.getFormattedDuration()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onRepeatModeChanged(repeatMode: Int) {}
|
override fun onRepeatModeChanged(repeatMode: Int) {}
|
||||||
|
|
||||||
|
@ -672,14 +681,10 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
}
|
}
|
||||||
|
|
||||||
mCurrTime = (mExoPlayer!!.duration / 1000).toInt()
|
mCurrTime = (mExoPlayer!!.duration / 1000).toInt()
|
||||||
if (listener?.videoEnded() == false && mConfig.loopVideos) {
|
|
||||||
playVideo()
|
|
||||||
} else {
|
|
||||||
mSeekBar.progress = mSeekBar.max
|
mSeekBar.progress = mSeekBar.max
|
||||||
mCurrTimeView.text = mDuration.getFormattedDuration()
|
mCurrTimeView.text = mDuration.getFormattedDuration()
|
||||||
pauseVideo()
|
pauseVideo()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun cleanup() {
|
private fun cleanup() {
|
||||||
pauseVideo()
|
pauseVideo()
|
||||||
|
|
Loading…
Reference in a new issue