moust / cordova-plugin-videoplayer

A Codova plugin to play video with the native MediaPlayer on Android devices.
MIT License
139 stars 102 forks source link

Stop playing video by touching the screen #63

Closed enzocandotti closed 4 years ago

enzocandotti commented 4 years ago

I'm using this plugin to play a video as a screensaver, so the idea is to stop the video by touching anywhere.

I know you implemented the close() method, but I can't call it whenever I want while the video is playing, because it opens on fullscreen, and I can't add a button or something like this.

Maybe I'm ignoring something, if you can think in a way to do it, I'd be grateful.

enzocandotti commented 4 years ago

I could do it modifying VideoPlayer.java, and adding this lines:

import android.view.View;
import android.view.View.OnTouchListener;
import android.view.MotionEvent;

//(line 143)
 videoView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                Log.d(LOG_TAG, "Touch while playing");
                player.stop();
                player.release();
                dialog.dismiss();

                return true;
            }
        });