Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to load stream in the desired position? #2197

Closed
Anton111111 opened this issue Dec 14, 2016 · 4 comments
Closed

How to load stream in the desired position? #2197

Anton111111 opened this issue Dec 14, 2016 · 4 comments
Labels

Comments

@Anton111111
Copy link
Contributor

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?

@ojw28
Copy link
Contributor

ojw28 commented Dec 14, 2016

You're probably using a media format that is not seekable. Please see the supported formats page. If you want to seek to a non-zero position, you need to use a container format that supports seeking.

@ojw28 ojw28 added the question label Dec 14, 2016
@Anton111111
Copy link
Contributor Author

But it jump to needed position after first frame. I use MP4.

@Anton111111
Copy link
Contributor Author

I'm sorry but I feel like an idiot. I need to use exoPlayer.prepare(videoSource, false, true); instead of exoPlayer.prepare(videoSource);

@ojw28
Copy link
Contributor

ojw28 commented Dec 14, 2016

Hah, yes, I was just writing a comment suggesting you tried that :). Glad you solved the issue!

@ojw28 ojw28 closed this as completed Dec 14, 2016
@google google locked and limited conversation to collaborators Jun 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants