Javascript Parser error

前端 未结 1 1628
醉酒成梦
醉酒成梦 2021-01-24 03:08

I have a HTML5 video that has a poster and a CSS play overlay button. I am trying to get the video to load once it has ended so that it shows the poster and the play overlay but

1条回答
  •  一向
    一向 (楼主)
    2021-01-24 03:41

    To prevent

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

    error, wrap if statement within click handler within setTimeout() call.

    See also 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);
    });
    
    
    click
    play pause

    0 讨论(0)
提交回复
热议问题