Exoplayer: How can I switch the video that I just add to the concatenatingmediasource while the exoplay is runing?

Created on 18 Dec 2018  路  9Comments  路  Source: google/ExoPlayer

How can I switch the video that I just add to the concatenatingmediasource while the exoplay is runing?
Can make it whihout reprepare the player?

question

Most helpful comment

If I understand your question correctly, you just need to seek to the new window after it has been added.
You can use the Runnable in addMediaSource to run something immediately after the source has been added:

concatenatingMediaSource.addMediaSource(
    newIndex, newMediaSource, () -> player.seekToDefaultPosition(newIndex));

All 9 comments

If I understand your question correctly, you just need to seek to the new window after it has been added.
You can use the Runnable in addMediaSource to run something immediately after the source has been added:

concatenatingMediaSource.addMediaSource(
    newIndex, newMediaSource, () -> player.seekToDefaultPosition(newIndex));

If I understand your question correctly, you just need to seek to the new window after it has been added.
You can use the Runnable in addMediaSource to run something immediately after the source has been added:

concatenatingMediaSource.addMediaSource(
    newIndex, newMediaSource, () -> player.seekToDefaultPosition(newIndex));

Thank you very much. It seems solve my problem.

@tonihei
when I call the
concatenatingMediaSource.addMediaSource( newIndex, newMediaSource, () -> player.seekToDefaultPosition(newIndex));
on the onPositionDiscontinuity

The screen will be black for a short time then it start to play the MediaSource that I just added.
How can I fix the black problem?

Here's what I do on onPositionDiscontinuity:

`
player.addListener(new Player.EventListener() {
@Override
public void onPositionDiscontinuity(int reason) {
int latestWindowIndex = player.getCurrentWindowIndex();
if (latestWindowIndex != lastWindowIndex) {
// item selected in playlist has changed, handle here
lastWindowIndex = latestWindowIndex;

      String addString=null;
      addString = new String("/storage/emulated/0/Download/3D_Rio_shark.MP4");
      MediaSource addMediaSource = buildMediaSource(Uri.parse(addString));

      int Size = mediaSource.getSize();
      mediaSource.addMediaSource(lastWindowIndex, addMediaSource, new Runnable() {
        @Override
        public void run() {
          player.seekToDefaultPosition(lastWindowIndex);
        }
      });
    }
  }
});

`

The black screen is visible because you seek to another source and the content needs to buffer first before we can continue playback. What would you expect to be visible during that time?

@tonihei
It would be very nice if the screen render the previous MediaSource's last frame which make it seamless/gapless visually.

previous MediaSource's last frame

If you seek after receiving a onPositionDiscontinuity event, you are already in a new media source and the frame that could potentially be displayed is the first frame in the media source which is not going to be played, but that doesn't seem to make much sense.

If your intention is to play this new item after the previous one (which played before receiving the onPositionDiscontinuity event), then you should probably insert the new source after this item and just let playback proceed automatically?

Can you try setting the keep_content_on_player_reset property of the PlayerView to true (or call PlayerView.setKeepContentOnPlayerReset(true)). That may help to keep the previous frame visible.

Reopened to track improving documentation for this method.

Closing as docs have been improved.

Was this page helpful?
0 / 5 - 0 ratings