Skip to content

How to load stream in the desired position? #2197

Closed
@Anton111111

Description

@Anton111111

I have several qualities of streams (http). Can i start laod new stream and start play in position where current playing.

How i try to do it:

public void changeQuality(String uri) {

        this.oldPosition = exoPlayer.getCurrentPosition();
        this.oldState = exoPlayer.getPlayWhenReady();

        DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context,
                userAgent, null);
        ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
        MediaSource videoSource = new ExtractorMediaSource(Uri.parse(uri),
        dataSourceFactory, extractorsFactory, null, null);
        exoPlayer.prepare(videoSource);
}

And on onPlayerStateChanged i seek to old position:

    @Override
    public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
      
        if (playbackState == ExoPlayer.STATE_READY) {
            if (this.oldPosition > -1) {
                exoPlayer.seekTo(this.oldPosition);
                this.oldPosition = -1;
                exoPlayer.setPlayWhenReady(this.oldState);
                }
            }
        }
    }

But it show first frame than jump to old position. How i can don't show first frame and start showing from old position?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions