我正在尝试用javascript和HTML5(就像游戏的介绍视频)在画布上绘制视频,这在网络浏览器上工作正常,但不能在Android上工作,所以我不确定我是否在某个地方犯了错误,或移动设备不支持此功能。
以下是代码:
//create canvas and get 2d context
var canvas = document.getElementById('introVid');
var ctx = canvas.getContext('2d');
// allow fullscreen
function fullscreen() {
var el = canvas;
if (el.webkitRequestFullScreen) {
el.webkitRequestFullScreen(); //chrome
} else {
el.mozRequestFullScreen(); //firefox
}
}
canvas.addEventListener("click", fullscreen); //enable fullscreen onClick
//draw the video into canvas
var video = document.getElementById("video");
video.addEventListener('loadeddata', function() {
video.play(); // start playing
update(); //start rendering
});
function update() {
ctx.drawImage(video, 0, 0, 300, 150);
requestAnimationFrame(update); //wait the browser be ready for next frame
};
这是一个关于小提琴的工作演示: http://jsfiddle.net/h1hjp0Lp/122/