ExoPlayer Restore State when Resumed

You can store the player position on pause:

position = player.getCurrentPosition(); //then, save it on the bundle.

And then when you restore it, if it is there, you can do:

if (position != C.TIME_UNSET) player.seekTo(position);

before prepare() in the initializePlayer() method.

Ok, I cloned the project, and made it work. What I changed basically is:

I added what I said before, and then:

position = C.TIME_UNSET;
if (savedInstanceState != null) {
    //...your code...
    position = savedInstanceState.getLong(SELECTED_POSITION, C.TIME_UNSET);
}

I made the videoUri global

videoUri = Uri.parse(steps.get(selectedIndex).getVideoURL());

Added onResume:

@Override
public void onResume() {
    super.onResume();
    if (videoUri != null)
        initializePlayer(videoUri);
}

Updated onPause:

@Override
public void onPause() {
    super.onPause();
    if (player != null) {
        position = player.getCurrentPosition();
        player.stop();
        player.release();
        player = null;
    }
}

And onSaveInstanceState:

currentState.putLong(SELECTED_POSITION, position);

Last, I removed onDetach onDestroyView onStop.

Obviously this is "just to make it work", you will have to work more on it.


I know this is an old thread but, here is my fix

 protected void onPause() {
    player.setPlayWhenReady(false);
    super.onPause();
}

protected void onResume() {
    player.setPlayWhenReady(true);
    super.onResume();
}

this will pause the video on activity pause and resume on activity resume.