html5视频的画布drawImage适用于浏览器,但不适用于Android

时间:2015-09-17 21:02:36

标签: javascript android html5-canvas html5-video

为什么此代码适用于普通浏览器,但为Android浏览器显示相同的屏幕截图?

HTML

<div class="video">
    <video id="video" src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4" muted controls autoplay></video>
</div>
<div class="timeline" id="timeline"></div>

的JavaScript

var timeline = document.getElementById('timeline'),
    video = document.getElementById('video'),
    interval = null;

video.addEventListener("playing", onStart);
video.addEventListener("pause", onStop);
video.addEventListener("ended", onEnd);

function onStart() {
    if (interval == null) {
        interval = window.setInterval(createImage, 1000);
    }
}

function onStop() {
    if (interval) {
        clearInterval(interval);
        interval = null;
    }
}

function onEnd() {
    onStop();
    video.removeEventListener("playing", onStart);
    video.removeEventListener("pause", onStop);
    video.removeEventListener("ended", onEnd);
}

function createImage() {
    console.log('createImage', video.currentTime, video.videoWidth, video.videoHeight);
    var canvas = document.createElement('canvas'),
        ctx = canvas.getContext('2d');
    ctx.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
    timeline.appendChild(canvas);
}

以下是完整代码: http://jsfiddle.net/kmturley/z99cmwtq/6/

1 个答案:

答案 0 :(得分:-1)

为什么这对我在chrome android 4.4.4中有用?

drawImage()

codepen