Javascript 预加载html 5画布中使用的视频

Javascript 预加载html 5画布中使用的视频,javascript,html,Javascript,Html,我得到了下面的代码在画布中使用视频,但我想知道是否可以预加载视频。完全下载,完成后播放。更好的是,以一定的百分比(比如80%)逐步下载 <!DOCTYPE html> <html land="en"> <head> <meta charset="utf-8"> <title>Using video in the canvas tag</title> <script type="text/javascript">

我得到了下面的代码在画布中使用视频,但我想知道是否可以预加载视频。完全下载,完成后播放。更好的是,以一定的百分比(比如80%)逐步下载

<!DOCTYPE html>

<html land="en">
<head>
<meta charset="utf-8">
<title>Using video in the canvas tag</title>
<script type="text/javascript">

    function init(){
        var can = document.getElementById('canvas1');
        var ctx = can.getContext('2d');

        var vid = document.createElement('video');
        vid.src = 'http://upload.wikimedia.org/wikipedia/commons/8/8c/Anthropoides_paradisea1.ogg';
        vid.autoplay = true;
        vid.loop = true;

        setInterval(function() {
            ctx.drawImage(vid, 0, 0);
        }, 60);
    }
</script>

</head>


<body onLoad="init();">
    <canvas id="canvas1" width="500" height="500"></canvas>

</body>


</html>

我相信你会对canplaythrough活动感兴趣。当它看起来已经加载了足够多的内容,如果以当前速率播放,它将在播放结束之前完全加载时触发

var vid, ctx;

function play() {
    vid.play();
    setInterval(function() {
        ctx.drawImage(vid, 0, 0);
    }, 60);
}

function init() {
    var can = document.getElementById('canvas1');
    ctx = can.getContext('2d');
    vid = document.createElement('video');
    vid.src = "http://upload.wikimedia.org/wikipedia/commons/8/8c/Anthropoides_paradisea1.ogg";
    vid.autoplay = false;
    vid.loop = true;
    vid.addEventListener("canplaythrough", play, false);
}


这是处理所有不同媒体元素事件的好资源:。

我相信您会对canplaythrough事件感兴趣。当它看起来已经加载了足够多的内容,如果以当前速率播放,它将在播放结束之前完全加载时触发

var vid, ctx;

function play() {
    vid.play();
    setInterval(function() {
        ctx.drawImage(vid, 0, 0);
    }, 60);
}

function init() {
    var can = document.getElementById('canvas1');
    ctx = can.getContext('2d');
    vid = document.createElement('video');
    vid.src = "http://upload.wikimedia.org/wikipedia/commons/8/8c/Anthropoides_paradisea1.ogg";
    vid.autoplay = false;
    vid.loop = true;
    vid.addEventListener("canplaythrough", play, false);
}


这是一个很好的资源,可以处理所有不同的媒体元素事件:。

啊,我对同一个概念很感兴趣,但我对音乐文件感兴趣!啊,我对同样的概念很感兴趣,但对音乐文件却不感兴趣!