I'm trying to create a custom video player. I use a VideoView to display my movie and a MediaController to control the video.
When the user tap on the screen it should show the header and the media controller for 3 s (or more if the user continue doing actions). And if the user tap again on the video it should hide both elements.
On the first tap on the screen the header and the controller show as I expected. My problem is that when I try to tap again on the screen it only hides the controller and the header doesn't disappear. I think this is because a MediaController defines its own tap surface so my question is how to change this ? How to change the tap surface of a MediaController object without coding my own MediaController ?
This is the code I use to to what I want :
private static final int ELAPSED_TIME = 2000;
private boolean visible;
@Override
public boolean onTouch(View v, MotionEvent event) {
// onTap
if (event.getAction() == MotionEvent.ACTION_DOWN) {
// Supprime le callback pour cacher les contrôles s'il y en avait un en cours
hideHandler.removeCallbacks(onElapsedTime);
// Affiche les contrôles s'il n'était pas déjà affichés
if (!visible) {
header.setVisibility(View.VISIBLE);
controller.show(0); // 0 -> Visible jusqu'à ce que hide() soit appelé
visible = true;
}
else {
header.setVisibility(View.GONE);
controller.hide();
visible = false;
}
// Défini un runnable a exécuter après ELAPSED_TIME pour cacher le header et le contrôleur
hideHandler.postDelayed(onElapsedTime, ELAPSED_TIME);
}
return true;
}
private Runnable onElapsedTime = new Runnable() {
public void run() {
header.setVisibility(View.GONE);
controller.hide();
visible = false;
}
};