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 {
|
||||
seekParameters = SeekParameters.CLOSEST_SYNC
|
||||
audioStreamType = C.STREAM_TYPE_MUSIC
|
||||
if (config.loopVideos) {
|
||||
repeatMode = Player.REPEAT_MODE_ONE
|
||||
}
|
||||
prepare(audioSource)
|
||||
}
|
||||
initExoPlayerListeners()
|
||||
|
@ -231,7 +234,13 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
|||
|
||||
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) {}
|
||||
|
||||
|
@ -338,13 +347,9 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
|
|||
|
||||
clearLastVideoSavedProgress()
|
||||
mCurrTime = (mExoPlayer!!.duration / 1000).toInt()
|
||||
if (config.loopVideos) {
|
||||
resumeVideo()
|
||||
} else {
|
||||
video_seekbar.progress = video_seekbar.max
|
||||
video_curr_time.text = mDuration.getFormattedDuration()
|
||||
pauseVideo()
|
||||
}
|
||||
video_seekbar.progress = video_seekbar.max
|
||||
video_curr_time.text = mDuration.getFormattedDuration()
|
||||
pauseVideo()
|
||||
}
|
||||
|
||||
private fun didVideoEnd(): Boolean {
|
||||
|
|
|
@ -317,6 +317,9 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
|||
|
||||
mExoPlayer = ExoPlayerFactory.newSimpleInstance(context)
|
||||
mExoPlayer!!.seekParameters = SeekParameters.CLOSEST_SYNC
|
||||
if (mConfig.loopVideos) {
|
||||
mExoPlayer?.repeatMode = Player.REPEAT_MODE_ONE
|
||||
}
|
||||
|
||||
val isContentUri = mMedium.path.startsWith("content://")
|
||||
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 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) {}
|
||||
|
||||
|
@ -672,13 +681,9 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
|||
}
|
||||
|
||||
mCurrTime = (mExoPlayer!!.duration / 1000).toInt()
|
||||
if (listener?.videoEnded() == false && mConfig.loopVideos) {
|
||||
playVideo()
|
||||
} else {
|
||||
mSeekBar.progress = mSeekBar.max
|
||||
mCurrTimeView.text = mDuration.getFormattedDuration()
|
||||
pauseVideo()
|
||||
}
|
||||
mSeekBar.progress = mSeekBar.max
|
||||
mCurrTimeView.text = mDuration.getFormattedDuration()
|
||||
pauseVideo()
|
||||
}
|
||||
|
||||
private fun cleanup() {
|
||||
|
|
Loading…
Reference in a new issue