簡體   English   中英

html5視頻的Canvas drawImage可在瀏覽器上運行,但不能在Android上運行

[英]Canvas drawImage of html5 video works on browsers but not Android

為什么此代碼在正常的瀏覽器上可以運行,但對於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/

在Chrome android 4.4.4中,這對我如何起作用?

drawImage()

碼筆

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM