Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exoplayer not looping the video

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.

like image 879
Edijae Crusar Avatar asked May 27 '17 12:05

Edijae Crusar


People also ask

How do you repeat a video on ExoPlayer?

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.

How do I play the next ExoPlayer video on Android?

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.

Can we play YouTube video in ExoPlayer Android?

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.


1 Answers

just use player.setRepeatMode(player.REPEAT_MODE_ONE);

like image 108
Sambhav jain Avatar answered Sep 30 '22 18:09

Sambhav jain