ExoPlayer seekto function does not seek to the specified point but starts from 0

491 views Asked by At

I'm working on ExoPlayer 2.6.0 for a Radio streaming app. Radio is playing is fine, but when i try to add seekTo for +/-30 seconds it always starts the streaming from 0. In the debug mode, player seeks to +30 seconds but as soon as setPlayWhenReady() is set it goes back to start from 0. It has been a long time i've been looking for this solution so decided to ask here. Any help will be appreciated.

Following is the code that i'm using for seekto operation.

ivForward.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                if (exoPlayer != null && Constants.isMediaPlaying) {
                    exoPlayer.setPlayWhenReady(false);
                    Constants.isMediaPlaying = false;
                    long bufferPosition = exoPlayer.getBufferedPosition();
                    long currentPosition = exoPlayer.getCurrentPosition();
                    if ((currentPosition + 30000) < bufferPosition + 50) {
                        exoPlayer.setPlayWhenReady(false);
                        Constants.isMediaPlaying = false;
                        exoPlayer.seekTo(exoPlayer.getCurrentWindowIndex(), currentPosition + 30000);
                        exoPlayer.setPlayWhenReady(true);
                        Constants.isMediaPlaying = true;
                    }
                }
            } catch (Exception e) {
                MakeToast.show("Error moving forward");
            }
        }
    });

Thanks

0

There are 0 answers