Android: Why can't I give an onClickListener to a VideoView?

前端 未结 11 2157
独厮守ぢ
独厮守ぢ 2021-02-03 17:08

I have written these lines of code:

 mVideoView = (VideoView) findViewById(R.id.video_view);
    mVideoView.setOnClickListener(new OnClickListener() {
        @O         


        
11条回答
  •  庸人自扰
    2021-02-03 17:45

    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;
        }
    });
    

提交回复
热议问题