I am developing a custom UI on top of ExoPlayer, and I noticed that the controls (PlaybackControlView
) hide when I touch the screen, not when I click.
I wanted to change to a click and checked how I can change the event listener, but so far could not find an easy solution. I checked the source SimpleExoPlayerView.java
and I noticed that it actually is hardcoded:
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (!useController || player == null || ev.getActionMasked() != MotionEvent.ACTION_DOWN) {
return false;
}
if (controller.isVisible()) {
controller.hide();
} else {
maybeShowController(true);
}
return true;
}
So far I could think of two solutions. One is to change the ExoPlayer's source code, but I do not like it since I will have to make modifications every time I update the ExoPlayer.
The second solution I could think of is simply to try to handle it myself, for example, to add my own listeners, and show and hide the controls myself. I have not tried this yet, but it seems possible.
Is there another better solution, like overriding the listeners, etc?
Update: I am using custom UI by inflating exo_playback_control_view.xml
By looking at this answer you can see that an
OnTouchListener#onTouch
is called BEFORE theView#onTouchEvent
so you can set anOnTouchListener
to the view, consume theMotionEvent
and it will not be passed onto theonTouchEvent
method.For example, using this code only "onTouch: LISTENER!!!" is logged when touching the view, and not "onTouchEvent: onTouchEvent!!!":
EDIT - to add your request for a click event handling I added the use of
GestureDetector
, using this answer - so now upon click "onSingleTapUp: TAP DETECTED" is logged as well.