编程语言
首页 > 编程语言> > JavaScript解析器错误

JavaScript解析器错误

作者:互联网

我有一个带有海报和CSS播放叠加按钮的HTML5视频.我正在尝试使视频在结束后立即加载,以便再次显示海报和播放叠加按钮.

我尝试了以下代码,但在最后一行遇到了解析器错误,有人可以帮助我,让我知道我做错了吗!

$(document).ready(function() {
  $('.video').parent().click(function () {
    if ($(this).children(".video").get(0).paused) {
      $(this).children(".video").get(0).play();
      $(this).children(".playpause").fadeOut();
    } else {
      $(this).children(".video").get(0).pause();
      $(this).children(".playpause").fadeIn();
    }
  });

  var video= $(".video").get(0);   
  video.addEventListener('ended',function () {
    video.load(); 
    $(".playpause").show();                              
  }, false);
});

解决方法:

阻止

Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause().

错误,请在setTimeout()调用内的点击处理程序中包装if语句.

另见How to prevent “The play() request was interrupted by a call to pause()” error?

$(document).ready(function() {
  $('.video').parent().click(function () {
    var vid = $(this).children(".video").get(0);
    setTimeout(function() {
    if (vid.paused) {
      vid.play();
      $(this).children(".playpause").fadeOut();
    } else {
      vid.pause();
      $(this).children(".playpause").fadeIn();
    }
    })
  });

  var video= $(".video").get(0);   
  video.addEventListener('ended',function () {
    video.load(); 
    $(".playpause").show();                              
  }, false);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
click<br>
<span class="playpause">play pause</span>
<video controls class="video" poster="https://placehold.it/350x150"  src="https://nickdesaulniers.github.io/netfix/demo/frag_bunny.mp4"></video>
</div>

标签:javascript,html5-video
来源: https://codeday.me/bug/20191014/1912374.html