How to pause playback and resume playing ExoPlayer 2 (PlayerControl has been removed)

In ExoPlayer < 2.x there was a PlayerControl class with pause() and resume() functions, but it was removed. I cannot find a way to do this on ExoPlayer 2 .

How to pause and resume playback?

+5
source share
2 answers

you can use void setPlayWhenReady(boolean playWhenReady); . If Exo is ready, bypassing false, you will stop the player. If you return, you will renew it. You can check the status of the player using getPlaybackState()

+19
source

This is my way. Create two methods and call them when necessary.

 private void pausePlayer(){ player.setPlayWhenReady(false); player.getPlaybackState(); } private void startPlayer(){ player.setPlayWhenReady(true); player.getPlaybackState(); } 

call them here

  @Override protected void onPause() { super.onPause(); pausePlayer(); } @Override protected void onResume() { super.onResume(); startPlayer(); } 
+3
source

Source: https://habr.com/ru/post/1259606/


All Articles