0

I build a page containing 6 videos. There is a thumbnail for each video, and when you click on the thumbnail, a custom lightbox covers the page with the video player in the middle. The video plays once the light box appears, and pauses when it closes.

I put this up about a month ago and all of a sudden I today the videos would no longer load. I keep getting 2 errors:

1. net::ERR_SPDY_PROTOCOL_ERROR

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

These errors are intermittent. The first is attached to the video file loading and always takes a second to appear.

my original code looked like this:

HTML

<div class="video_page_video_wrap">
    <h3>{{ widget.video_title }}</h3>
<a href="#" class="video_link" onclick="popup_video(this)">

    <img src="{{ widget.video_thumbnail.src }}" alt="{{ widget.video_thumbnail.alt }}">

</a>
<div class="video_container">
    <div class="video_wrap">
        <div class="video_close">X Close</div>
        <video autoplay class="step_video" loop controls>
            <source src="{{ widget.video_mp4_url }}" type="video/mp4">
            <source src="{{ widget.video_webm_url }}" type="video/webm">
        </video>
    </div>
</div>

</div>

Javascript

$('.step_video').each(function() {

    var video = $(this).get(0);

    video.pause();

});

function popup_video(i) {
    var video_con = $(i).siblings('.video_container');
    var video_wrap = video_con.children('.video_wrap');
    var video = video_con.find('.step_video').get(0);
    var close = video_con.find('.video_close');

    video_con.show();
    video.play();

    close.on('click touch', function() {

        video_con.hide();
        video.pause();

    });

    if (video_con.is(":visible")){

        $(video_con).on("click touch", function(){

            video_con.hide();
            video.pause();

        });

        video_wrap.on("click touch", function(e){
            e.stopPropagation();
        });

    }

}

All I could tell from research is that for some reason the play promise was being interfered with by the pause function (?), so I altered this a bit.

I set preload to none on the video player, removed the initial pause on the videos in my javascript because the videos loading was blocked, then I loaded the video when the function is fired before playing the video:

HTML

<div class="video_page_video_wrap">
    <h3>{{ widget.video_title }}</h3>
<a href="#" class="video_link" onclick="popup_video(this)">

    <img src="{{ widget.video_thumbnail.src }}" alt="{{ widget.video_thumbnail.alt }}">

</a>
<div class="video_container">
    <div class="video_wrap">
        <div class="video_close">X Close</div>
        <video class="step_video" loop controls preload="none">
            <source src="{{ widget.video_mp4_url }}" type="video/mp4">
            <source src="{{ widget.video_webm_url }}" type="video/webm">
        </video>
    </div>
</div>

</div>

Javascript

$('.step_video').each(function() {

    var video = $(this).get(0);

});


function popup_video(i) {
    var video_con = $(i).siblings('.video_container');
    var video_wrap = video_con.children('.video_wrap');
    var video = video_con.find('.step_video').get(0);
    var close = video_con.find('.video_close');

    video.load();

    video_con.show();

    video.play();

    close.on('click touch', function() {

        video_con.hide();
        video.pause();

    });

    if (video_con.is(":visible")){

        $(video_con).on("click touch", function(){

            video_con.hide();
            video.pause();

        });

        video_wrap.on("click touch", function(e){
            e.stopPropagation();
        });

    }

}

The videos are now playing when you click their thumbnail (again) however it seems like they are taking quite a few seconds to load and do not play until they are loaded (from what I can tell). Before they would play immediately. You can see the page here: http://www.icoachfirst.com/videos using the last version of the code.

I am thinking that the server is just having a bad day and the slow file serving is causing the play/pause functions to trip up, and my last revision to the code has made it slow down worse by requiring the video to load before playing. I'm lost in this though.

tRuEsAtM
  • 3,517
  • 6
  • 43
  • 83
JSum
  • 597
  • 9
  • 20
  • Possible duplicate of [How to prevent "The play() request was interrupted by a call to pause()" error?](https://stackoverflow.com/questions/36803176/how-to-prevent-the-play-request-was-interrupted-by-a-call-to-pause-error) – Muhammad Omer Aslam Nov 20 '17 at 21:51
  • That's a small part of my issue and no longer a factor.... – JSum Nov 20 '17 at 21:52
  • for me they never play, as per your given link, when i click on `Agile Goal Setting` video it open a popup and the pause button is shown which means the attempt to play has been started but even after 5 mins the video never plays , and if i try to click on the pause button i get the error `Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause().` – Muhammad Omer Aslam Nov 20 '17 at 21:56
  • oh... well they start after between 5 and 15 seconds for me and the pause button works... – JSum Nov 20 '17 at 21:59
  • between i am using `Google Chrome is up to date Version 62.0.3202.94 (Official Build) (64-bit)` windows 10 – Muhammad Omer Aslam Nov 20 '17 at 22:00
  • I have the same browser version and build. – JSum Nov 20 '17 at 22:01
  • one thing I have noticed is that when you click the play button it starts downloading the whole file rather than starting playback with buffer maybe that's one of the problems with the late playback start, have you tried using `video.addEventListener("canplaythrough", function() { // Ready to play the whole video? }, false);` rather than waiting for the whole meadia to load see here for `ajax and bloburl` options in the end http://dinbror.dk/blog/how-to-preload-entire-html5-video-before-play-solved/ – Muhammad Omer Aslam Nov 20 '17 at 22:09
  • I added this to my script with an alert to the console. it didn't seam to make it any faster but it does allow me to see that it is loading that is slowing it down. – JSum Nov 20 '17 at 22:15
  • have you looked into the link http://dinbror.dk/blog/how-to-preload-entire-html5-video-before-play-solved/ try removing the `video.load()` calls it uses un-necessary bandwidth loading the video from the server – Muhammad Omer Aslam Nov 20 '17 at 22:22
  • this might help you out https://stackoverflow.com/questions/10328401/html5-how-to-stream-large-mp4-files – Muhammad Omer Aslam Nov 20 '17 at 22:25

0 Answers0