HTML5 Video not looping

后端 未结 5 1182
粉色の甜心
粉色の甜心 2021-02-04 19:09

I\'m having a weird problem. My two versions of chrome(regular & canary) refuse to loop the video i\'m showing. Or well, sometimes they loop it twice and stops after that. W

5条回答
  •  余生分开走
    2021-02-04 19:17

    I have recently had some issue with this myself. It turned out to be something to do with my site being on localhost. When I move the site to my production server and tested remotely it all worked as expected.

    To force it to work on localhost, I used the solution from Joakim Bananskal, but playing the video cause an error because it was already trying to play it, so I just had to reset the video first using load().

    Having it set to loop also seemed to cause an issue, because the video never fired the ended event.

    My final solution for localhost is below:

    $("video").each(function () {
        this.loop = false;
        this.onended = function () {
            this.load();
        };
        this.play();
    });
    

    with this HTML:

    
    

提交回复
热议问题