【发布时间】:2015-12-14 21:20:15
【问题描述】:
为什么这段代码可以在普通浏览器上运行,但在 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);
}
【问题讨论】:
-
啊,是的,可能是视频编解码器的问题
-
不幸的是,对于 mp4 和 webm 视频,Lollipop 之前的设备 (
-
您尝试过使用 webm 视频吗?看来这可能是浏览器支持的视频编解码器的问题
标签: javascript android html5-canvas html5-video