Sto cercando di utilizzare il metodo drawImage
della tela con origine video, ma non funziona in Android 4.4.2, testato con il browser Chrome.HTML5 Canvas drawImage con sorgente video non funzionante su Android
Ecco il mio codice:
$(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);
}
});
Fiddle:http://jsfiddle.net/h1hjp0Lp/
C'è un modo per fare che funziona con i dispositivi Android e iOS come bene?
provare a sostituire 'evento click' con' touchstart', vedere se funziona. – Allen
@ Allen, grazie, ma non funziona. – vitozev
leggendo questo, sembra che ci sia un bug in Chrome Mobile. Ho appena controllato la demo precedente che ho fatto con Video -> Canvas e non funzionano più. Continuerò a indagare. (Android 5.1) – rlemon