-
Notifications
You must be signed in to change notification settings - Fork 4
/
canvascaptureopaque.html
73 lines (59 loc) · 2.11 KB
/
canvascaptureopaque.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>HTMLCanvasElement capture into MediaStream demo</title>
</head>
<body>
<div> Create Real-Time stream from < canvas > and play it back.</div>
</body>
<video id="v" muted="true" hidden controls autoplay loop>
<source src="big-buck-bunny_trailer.webm" type="video/webm" />
</video>
<canvas id="c" width="1280" height="720"></canvas>
<div id="div1"> </div>
</br>
<button id="btn1" onclick="startStreaming()">Create Stream from < canvas ></button>
<script type="text/javascript" src="dimsum.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function(){
var v = document.getElementById('v');
// c = document.createElement('canvas');
// document.getElementById('div1').appendChild(c);
c = document.getElementById('c');
// c.hidden = true;
var context = c.getContext('2d', {alpha: false});
v.addEventListener('play', function(){
draw(this,context,c.clientWidth,c.clientHeight);
},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);
}
var c;
var theStream;
var thePlayback;
function startStreaming() {
document.getElementById("btn1").disabled = true;
// Create a MediaStream out of the <canvas> tag.
theStream = c.captureStream();
document.body.appendChild(document.createElement("br"));
createButton("btn2", "Play back captured Stream to a <video>", startPlayback);
document.body.appendChild(document.createElement("br"));
}
function startPlayback() {
document.getElementById("btn2").disabled = true;
// And plug the created MediaStream into another <video> tag.
createVideoTag("playbackTag", 1136, 640, theStream);
thePlayback = document.getElementById("playbackTag");
document.body.appendChild(document.createElement("br"));
createButton("btn3", "Stop theStream captured from <canvas>", stopStreaming);
}
function stopStreaming() {
document.getElementById("btn3").disabled = true;
theStream.getVideoTracks()[0].stop();
}
</script>
</html>