0

After loading a video, it starts to play. I want the video to be paused for the very first time after loading. If the user clicks on the resume button it must start to play. How can I achieve this for exoplayer2.ui.PlayerView?

Robbit
  • 4,128
  • 1
  • 10
  • 28
Roy9711
  • 1
  • 3

1 Answers1

0

I want the video to be paused for the very first time after loading

You can use player.setPlayWhenReady(false); when you init your Player.

If the user clicks on the resume button it must start to play.

You can add a ControlDispatcher in your PlayView by calling setControlDispatcher(@Nullable ControlDispatcher controlDispatcher) method, like playerView.setControlDispatcher(new MyDefaultControlDispatcher());

The class MyDefaultControlDispatcher is my Custom ControlDispatcher, as below:

private class MyDefaultControlDispatcher extends DefaultControlDispatcher {

    @Override
    public boolean dispatchSetPlayWhenReady(Player player, boolean playWhenReady) {
        super.dispatchSetPlayWhenReady(player, playWhenReady);
    if (playWhenReady && player.getPlaybackState() == Player.STATE_READY) {
        player.setPlayWhenReady(true);
    }
        return true;
    }
}

You can inherit the DefaultControlDispatcher to Override your favorite method , like dispatchSetPlayWhenReady, OR implement the interface ControlDispatcher.

The method dispatchSetPlayWhenReady will get your click event on the play/stop button in your PlayView. You can verify it in your PlayerControlView's OnClick method. I will show your picture as below: enter image description here

PS: Like @ahmedaljubair has mentioned that the method setPlayWhenReady only work when the player is in the ready state. So, you need check the player's state when you call the setPlayWhenReady method to pause and resume your player.

Robbit
  • 4,128
  • 1
  • 10
  • 28