0

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;
    }
};
Fr4nz
  • 1,616
  • 6
  • 24
  • 33
  • Copy [MediaController.java](http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.3_r1/android/widget/MediaController.java#MediaController), & modify it if you don't like the behavior & you can't fix it by what you are doing. Visible controller probably consumes all the touch events and you would need to hook into the touch handling somehow – zapl May 08 '12 at 12:30
  • I wanted to try what you said but it requires a lot of dependencies so I don't think it's a good idea. I just want to add a header that will hide and show at the same time as the mediacontroller but apparently it's not so easy. – Fr4nz May 22 '12 at 13:20
  • MediaController.java relies on internal APIs; so it's not even an option to try to import all the dependency files - you'd have to find a way to re-create the "floating window" functionality of MediaController without PolicyManager.makeNewWindow(mContext); – MaximumGoat Jun 01 '12 at 19:48

1 Answers1

1

First construct your class and extend MediaController. Now, Override "hide" and "show" methods and do what you want to do. Its simple , I have done the same thing. In the hide method u can set the visiblity of your header as Gone or invisible(depends on your requiremnets).

prateek
  • 440
  • 4
  • 12