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?
-
add code what you have tried . – Nikunj Paradva Jul 01 '19 at 10:29
-
3Did you try `player.setPlayWhenReady(false)` ? – ysfcyln Jul 01 '19 at 10:45
-
1https://exoplayer.dev/listening-to-player-events.html – Vivek Mishra Jul 01 '19 at 11:17
1 Answers
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:
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.

- 4,300
- 1
- 13
- 29