js控制video的播放和暂停


  var videoEl = document.querySelector('video')
             videoEl.addEventListener('play', function () {
                 var vTime = videoEl.currentTime
                 if (vTime > 12) {  //视频播放到12秒需要执行操作 

                     videoEl.currentTime = 0
                 }
              if (vTime == total_vtime) {
                          //视频播放完需要执行操作

                        }

             })
             videoEl.addEventListener('timeupdate', function () {
                 var vTime = videoEl.currentTime;
                 var total_vtime = videoEl.duration;
                 if (vTime ==total_vtime) {
                    //视频播放完需要执行操作
                     //videoEl.currentTime = 0
                     //videoEl.pause()//播放暂停
                 }
             })

你可能感兴趣的:(web前端开发,js相关)