Say,I'm displaying video in canvas and want to stop it whenever mousehover it.I have tried a lot, Please help what is problem in code?It also doesn't giving any error.
<!DOCTYPE html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<title>Playing YouTube video on HTML5 canvas</title>
<meta name="viewport" content="user-scalable=no, initial-scale=1.0, maximum-scale=1.0, width=device-width" />
<style type="text/css">
html, body {
width: 50%;
height: 50%;
padding: 0px;
margin: 0px;
}
#canvas {
padding: 0px;
margin: 0px;
top:0;
left:0;
z-index: -1;
position: absolute;
width: 50%;
height: 50%;
}
</style>
</head>
<body>
<div style="display: none;">
<video id="video" autoplay="true" loop="true" >
<source src="video/browser.ogg" type="video/ogg" />
<source src="video/browser.mp4" type="video/mp4" />
</video>
</div>
<canvas id="canvas1"></canvas>
<script>
document.addEventListener('DOMContentLoaded', function(){
var v = document.getElementById('video');
var canvas = document.getElementById('canvas1');
var context = canvas.getContext('2d');
//var cw = Math.floor(canvas.clientWidth / 100);
//var ch = Math.floor(canvas.clientHeight / 100);
var cw = Math.floor(canvas.clientWidth);
var ch = Math.floor(canvas.clientHeight);
canvas.width = cw;
canvas.height = ch;
v.addEventListener('play', function(){
draw(this,context,cw,ch);
},false);
},false);
function draw(v,c,w,h) {
if(v.paused || v.ended) return false;
c.drawImage(v,0,0,w,h);
setTimeout(draw,20,v,c,w,h);
}
function initialise(){
var canvas=document.getElementById("canvas1");
canvas.addEventListeer("mousehover", fary, false);
}
function fary(event){
video.pause({left:event.pageX-200,top:event.pageY+100});
};
</script>
</body>
</html>
When I using above code it also not displaying video but audio hears,and when I remove few lines in last it display but doesn't work. Please help
function initialise(){
var canvas=document.getElementById("canvas1");
canvas.addEventListeer("mousehover", fary, false);
}
function fary(event){
video.pause({left:event.pageX-200,top:event.pageY+100});
};