简体   繁体   English

带有闪光灯的HTML5视频循环

[英]Html5 video loop with a flash

I have a video on a page that needs to loop infinitely in all browsers . 我在页面上有一个视频, 需要在所有浏览器中无限循环 I gave up trying to use loop atribute in video tag as that didn't work correctly in all browsers and blocked my JS. 放弃尝试在视频代码中使用循环归因 ,因为在所有浏览器中均无法正常工作,因此我屏蔽了JS。 JS could not detect that the video ended, I guess. 我想JS无法检测到视频已结束。

I use the following code. 我使用以下代码。

HTML: HTML:

<video autoplay="" preload="auto" poster="file" id="id">
   <source src="..." type="video/webm">
   <source src="..." type="video/mp4">
   <source src="..." type="video/ogg">
   <img src="..." title="Lundegaard" alt="Video fallback">
   Your browser does not support the video tag.
</video>

JS: JS:

/* video infinite loop */
$('video').bind("ended", function() {
    this.load();
    this.play();
});

This solution is fine, except for the moment when the video RELOAD again, causing a blank space appears for a while . 此解决方案很好,除了再次重新加载视频而导致空白出现一会儿的那一刻。 I guess that once the video is initially loaded, there is no need to load it again. 我猜想,一旦视频最初被加载,就无需再次加载。 Without this.load() the loop is not working. 没有this.load() ,循环将无法正常工作。

Do u have any idea how to achieve the looping without that empty space flash? 您是否知道如何在没有空白闪存的情况下实现循环?

Thank u! 感谢你!

Partial solution 部分解决方案

I have found out there is a problem with Chrome. 我发现Chrome存在问题。 In case of Chrome browser, this.play() is not working for some reason, but it is working in other browsers. 如果是Chrome浏览器,则this.play()出于某种原因无法正常运行,但可以在其他浏览器中正常运行。 So I partially fixed it with following code. 所以我用下面的代码部分修复了它。 I am open to better solutions. 我愿意寻求更好的解决方案。

function videoLoop() {
    var video = $('video#id');

    //Chrome is not working with this.play() only
    var isChrome = !!window.chrome;

    video.bind("ended", function() {
        if (isChrome) {
            this.load();
        }
        this.play();
    });
};

Try adding loop to your video markup: 尝试在视频标记中添加loop

<video autoplay="" loop preload="auto" poster="file" id="id">
...

Edit: 编辑:

After see your comment, you can achieve it using your current code, but you have to remove this.load() line to avoid that blank space. 在看到您的注释之后,您可以使用当前代码来实现它,但是您必须删除this.load()行以避免空格。 It would look as this: 它看起来像这样:

$('video').on('ended', function(){
    this.play();
});

jsFiddle jsFiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM