简体   繁体   English

使用HTML5视频循环预加载网站

[英]Preloading site with HTML5 video loop

I am developing a site that uses a large section with a video background. 我正在开发一个使用大部分视频背景的网站。 The background is set to loop. 背景设置为循环。 We also wanted to implement an preloading image while the site was loading resources. 我们还想在站点加载资源时实现预加载映像。

The basic structure is just some simple jQuery: 基本结构只是一些简单的jQuery:

$(window).load(function() {
$(".loader").fadeOut("slow");
})

and HTML: 和HTML:

<div class="loader"></div>

right after the body tag. body标签之后。

The problem with this is that the server sends multiple '206 partial content' packets to the browser and the preloading image just hangs around because I believe the server is sending small packets of the video to load or it's just requesting the file over and over - I really can't tell. 这个问题是服务器将多个“ 206部分内容”数据包发送到浏览器,并且预加载图像只是挂起,因为我认为服务器正在发送视频的小数据包以进行加载,或者只是一遍又一遍地请求文件-我真的不知道

I've tried to think of some way around this, but after hours of searching I haven't come up with any solutions. 我试图考虑一些解决方法,但是经过数小时的搜索,我没有提出任何解决方案。

I'm wondering if there is a way to have this script maybe ignore the <video> tag and just wait for the page to load the other resources? 我想知道是否有一种方法可以让此脚本忽略<video>标记,而仅等待页面加载其他资源?

I've had success building out the video in JS and then using imagesLoaded to play. 我已经成功地用JS构建了视频,然后使用imagesLoaded进行播放。 I didn't test the code below, but I think it'll work. 我没有测试下面的代码,但是我认为它可以工作。

https://github.com/desandro/imagesloaded https://github.com/desandro/imagesloaded

    var videoWrap = document.getElementById('videoWrap'); 
    var video = document.createElement('video');
    videoWrap.appendChild(video);       
    video.setAttribute("id","myVideo");
    video.controls = false; 

    if ( video.canPlayType('video/mp4') ) {
        video.src = '/path/video.mp4'; 
    } else {
        video.src = '/path/video.ogg'; 
    }

    video.load();

    /*
    video.oncanplaythrough = (function(){
        // useful for some stuff
    })();
    */

    $('#imagesContainer').imagesLoaded( function() {
        video.play();
    });

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

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