I'm using Exoplayer in my android app to play video and audio files. according to Exoplayer developer's guide,in order to loop a video/audio, this is what you have to do
MediaSource mediaSource = new ExtractorMediaSource(videoUri, ...);
// Loops the video indefinitely.
LoopingMediaSource loopingSource = new LoopingMediaSource(mediaSource);
So I implemented it like this in my Activity's onCreate method
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 = new ExtractorMediaSource(videoUri,dataSourceFactory, extractorsFactory, null, null);
loopingSource = new LoopingMediaSource(mediaSource);
simpleExoPlayer.prepare(mediaSource);
But looping of my video file is not taking place. it just plays once.
To loop a MediaSource indefinitely, use Player. setRepeatMode(int) instead of this class. To add a MediaSource a specific number of times to the playlist, use ExoPlayer.
Show activity on this post. 3] Just check by clicking next button from the media controller if that works then you are done, now the videos will be played automatically once finished the current one.
ExoPlayer is an app-level media player built on top of low-level media APIs in Android. It is an open source project used by Google apps, including YouTube and Google TV.
just use player.setRepeatMode(player.REPEAT_MODE_ONE);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With