I have written these lines of code:
mVideoView = (VideoView) findViewById(R.id.video_view);
mVideoView.setOnClickListener(new OnClickListener() {
@O
This is probably long overdue, nonetheless of some help to those who may run into a similar problem. The way I got around this problem was by laying a transparent image view right on top of the video view, then listening to onClick events on the image view, and doing whatever it was I wanted to do with the video view afterwards.
You can solve this issue through cover layout. I used the linearlayout.
<LinearLayout
android:id="@+id/video1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<VideoView
android:id="@+id/video2"
android:layout_width="370dp"
android:layout_height="180dp"
android:layout_gravity="center"
app:elevation = "0dp"
android:background="@mipmap/video"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:visibility="visible"
/>
</LinearLayout>
and try it in source file.
video1.setOnClickListener {
if(Video.isPlaying) {
Video.pause()
}
else {
Video.start()
}
}
Here's how I solved the pause/play of VideoViews using onTouch:
// Class variables
private boolean bVideoIsBeingTouched = false;
private Handler mHandler = new Handler();
vvVideo.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (!bVideoIsBeingTouched) {
bVideoIsBeingTouched = true;
if (vvVideo.isPlaying()) {
vvVideo.pause();
} else {
vvVideo.resume();
}
mHandler.postDelayed(new Runnable() {
public void run() {
bVideoIsBeingTouched = false;
}
}, 100);
}
return true;
}
});
You might try Gesture Overlay View
You should be able to overlay this view on top of another view in order to get touch events.
Hope this helps!
use VideoView.setOnTouchListener(..)
it works for VideoView