Detect if HTML5 Video element is playing

后端 未结 16 2563
被撕碎了的回忆
被撕碎了的回忆 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:23

    This is my code - by calling the function play() the video plays or pauses and the button image is changed.

    By calling the function volume() the volume is turned on/off and the button image also changes.

    function play() { 
      var video = document.getElementById('slidevideo'); 
      if (video.paused) {
        video.play()
        play_img.src = 'img/pause.png'; 
      }
      else {
        video.pause()
        play_img.src = 'img/play.png';
      }
    }
    
    function volume() { 
      var video = document.getElementById('slidevideo');
      var img = document.getElementById('volume_img');
      if (video.volume > 0) {
        video.volume = 0
        volume_img.src = 'img/volume_off.png';  
      }
      else {
        video.volume = 1
        volume_img.src = 'img/volume_on.png';
      }
    }
    

提交回复
热议问题