Exoplayer not looping the video
You can simply set repeat mode as "Repeat_MODE_ONE".
Example for Kotlin:
val player: SimpleExoPlayer = ExoPlayerFactory.newSimpleInstance(
context,
DefaultRenderersFactory(context),
DefaultTrackSelector(),
DefaultLoadControl()
).apply {
repeatMode = Player.REPEAT_MODE_ONE
}
p.s.The player is from com.google.android.exoplayer2
I discovered that there was some crucial info left out in Exoplayer developers guide. after creating LoopingMediaSource
instance, one should not call simpleExoPlayer.prepare(mediaSource);
but instead call simpleExoPlayer.prepare(loopingSource);
. below is the complete code
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory factory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector = new DefaultTrackSelector(factory);
simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(this,trackSelector);
simpleExoPlayer.setPlayWhenReady(true);
simpleExoPlayerView.setPlayer(simpleExoPlayer);
// Measures bandwidth during playback. Can be null if not required.
bandwidthMeter2 = new DefaultBandwidthMeter();
// Produces DataSource instances through which media data is loaded.
dataSourceFactory = new DefaultDataSourceFactory(this,
Util.getUserAgent(this, applicationName), bandwidthMeter2);
// Produces Extractor instances for parsing the media data.
extractorsFactory = new DefaultExtractorsFactory();
MediaSource mediaSource = new ExtractorMediaSource(videoUri,dataSourceFactory, extractorsFactory, null, null);
// Loops the video indefinitely.
LoopingMediaSource loopingSource = new LoopingMediaSource(mediaSource);
simpleExoPlayer.prepare(loopingSource);
just use player.setRepeatMode(player.REPEAT_MODE_ONE);