Detect if HTML5 Video element is playing

后端 未结 16 2444
被撕碎了的回忆
被撕碎了的回忆 2020-11-29 00:43

I\'ve looked through a couple of questions to find out if an HTML5 element is playing, but can\'t find the answer. I\'ve looked at the W3 documentation and it has an event n

16条回答
  •  自闭症患者
    2020-11-29 01:19

    I just did it very simply using onpause and onplay properties of the html video tag. Create some javascript function to toggle a global variable so that the page knows the status of the video for other functions.

    Javascript below:

       // onPause function
       function videoPause() {
          videoPlaying = 0;
       }
    
       // onPause function
       function videoPlay() {
          videoPlaying = 1;
       }
    

    Html video tag:

    
    

    than you can use onclick javascript to do something depending on the status variable in this case videoPlaying.

    hope this helps...

提交回复
热议问题