带有视频源的HTML5 Canvas drawImage无法在Android上运行

kav*_*kav 6 video html5 android canvas drawimage

我正在尝试将canvas的drawImage方法与视频源一起使用,但它在使用Chrome浏览器测试的Android 4.4.2中无效.

这是我的代码:

$(function() {

    var canvas = document.getElementById('canvas');
    var ctx = canvas.getContext('2d');
    var video = document.getElementById('video');

    var videoWidth; 
    var videoHeight;    

    var paused = false;

    canvas.addEventListener('click', function() {   
        if (paused) {
            video.play(); 
        } else {
            video.pause();
        }
        paused = !paused;
    });

    video.addEventListener("loadedmetadata", function() {
        videoWidth = this.videoWidth || this.width;
        videoHeight = this.videoHeight || this.height;
        canvas.width = videoWidth;
        canvas.height = videoHeight;
    }, false);

    video.addEventListener('play', function() {
        var $this = this; // cache
        (function loop() {
            if ( ! $this.paused && ! $this.ended ) {
                drawImage($this);
                requestAnimationFrame(loop);
                // setTimeout(loop, 1000 / 25); // drawing at 25 fps
            }
        })();
    }, 0);

    function drawImage(frame) {
        ctx.drawImage(frame, 0, 0);
        // ctx.clearRect ( 0 , 0 , canvas.width, canvas.height );
    }

});
Run Code Online (Sandbox Code Playgroud)

小提琴: http ://jsfiddle.net/h1hjp0Lp/

有没有办法使它适用于Android和iOS设备?

Sim*_*ris 2

这似乎是特定文件格式 ( ) 的问题mp4

替换一个webm文件就可以正常工作了。

不幸的是,但这已经有<video>一段时间了(真正需要 webm/ogg 而不仅仅是 mp4,无论浏览器声称支持什么)。

(我敢打赌这是一个与反 DRM 截图相关的错误?谁知道)

例如使用源代码http://video.webmfiles.org/big-buck-bunny_trailer.webm,它将起作用:http://jsfiddle.net/h1hjp0Lp/15/