Let ExoPlayer handle video looping seamlessly
Now that videos are replacing the inefficient GIF format, gapless loops are important. ExoPlayer's built-in mechanism prebuffers the video to enable this, whereas the current implementation of seeking to the start presents a short but noticeable delay between each loop. Note that this change introduces an incompatibility with current behaviour: due to google/ExoPlayer#6459, certain videos with broken audio tracks that played fine before will no longer start. Disabling the audio track is a workaround to re-enable looping playback, but ExoPlayer does not appear to expose a way to check if the audio track is short enough to produce the bug.
This commit is contained in:
parent
035d0363e3
commit
f8315438d8
2 changed files with 6 additions and 0 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()
|
||||||
|
|
|
@ -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))
|
||||||
|
|
Loading…
Reference in a new issue