Skip to content Skip to sidebar Skip to footer

How To Play A Particular Video From Exoplayer Playlist Android?

I'm using ExoPlayer to play a list of videos as playlist: MediaSource[] mediaSources = new MediaSource[mList.size()]; for (int i = 0; i < mList.size(); i++) { me

Solution 1:

You may want to use seekTo(windowIndex, positionMs).

player.prepare(mediaSource);
player.seek(3, C.TIME_UNSET);
player.setPlayWhenReady(true);

Solution 2:

Here is a sample code that plays video in a particular position from the list when click.

//Pass the position of the item on the listview/playlist from previous activity /fragment.Intent_intent= getIntent();
    position = _intent.getIntExtra("postion_id", 0);

    player = ExoPlayerFactory.newSimpleInstance(this, newDefaultTrackSelector());

    playerView.setPlayer(player);

    DefaultDataSourceFactorydataSourceFactory=newDefaultDataSourceFactory (this, Util.getUserAgent(this, "exo-demo"));

    ConcatenatingMediaSourceconcatenatingMediaSource=newConcatenatingMediaSource();

    //Ensure to populate the allFiles array.for (inti=0; i < allFiles.size(); i++) {

        FilecurrentFile=newFile(allFiles.get(i));

        MediaSourcemediaSource=newExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse("file://" + currentFile.getAbsolutePath()));
        concatenatingMediaSource.addMediaSource(mediaSource);

    }
    player.prepare(concatenatingMediaSource);
    //Play from the item selected on the playlist from previous activity/fragment
    player.seekTo(position, C.TIME_UNSET);
    player.setPlayWhenReady(true);


    player.addListener(newPlayer.EventListener() {
        @OverridepublicvoidonTimelineChanged(Timeline timeline, Object manifest, int reason) {



        }

        @OverridepublicvoidonTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {

        }

        @OverridepublicvoidonLoadingChanged(boolean isLoading) {

        }

        @OverridepublicvoidonPlayerStateChanged(boolean playWhenReady, int playbackState) {

        }

        @OverridepublicvoidonRepeatModeChanged(int repeatMode) {

        }

        @OverridepublicvoidonShuffleModeEnabledChanged(boolean shuffleModeEnabled) {

        }

        @OverridepublicvoidonPlayerError(ExoPlaybackException error) {

        }

        @OverridepublicvoidonPositionDiscontinuity(int reason) {
            //THIS METHOD GETS CALLED FOR EVERY NEW SOURCE THAT IS PLAYEDintlatestWindowIndex= player.getCurrentWindowIndex();
            if (latestWindowIndex != position) {
                // item selected in playlist has changed, handle here
                position = latestWindowIndex;
                // ...
            }




        }

        @OverridepublicvoidonPlaybackParametersChanged(PlaybackParameters playbackParameters) {

        }

        @OverridepublicvoidonSeekProcessed() {

        }
    });

Post a Comment for "How To Play A Particular Video From Exoplayer Playlist Android?"