我正在尝试将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 );
}
});
小提琴: http : //jsfiddle.net/h1hjp0Lp/
有没有办法使其也可以与Android和iOS设备一起使用?
该特定文件格式(mp4
)似乎有问题。
替换一个webm
文件,它可以正常工作。
不幸的是,但这已经有<video>
一段时间了(不管浏览器声称支持什么,实际上都需要webm / ogg而不是mp4)。
(我敢打赌它是一个与反Drm屏幕截图相关的错误?谁知道)
例如使用源http://video.webmfiles.org/big-buck-bunny_trailer.webm
,它将起作用:http : //jsfiddle.net/h1hjp0Lp/15/
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句