Skip to content

Commit ad6df8b

Browse files
committed
adding the gum demos
1 parent 2d7926f commit ad6df8b

File tree

6 files changed

+82
-22
lines changed

6 files changed

+82
-22
lines changed

assets/remy-and-ellis2.mp4

455 KB
Binary file not shown.

assets/remy-and-ellis2.webm

188 KB
Binary file not shown.

demos.json

+20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
11
[
2+
{
3+
"desc": "Stream video and filter with canvas",
4+
"url": "gum-canvas",
5+
"tags": "getUserMedia canvas",
6+
"support": {
7+
"live": "",
8+
"nightly": "chrome opera"
9+
},
10+
"test": "navigator.getUserMedia !== undefined"
11+
},
12+
{
13+
"desc": "Stream video to the browser<br><small>Also works on Opera Mobile 12</small>",
14+
"url": "gum",
15+
"tags": "getUserMedia",
16+
"support": {
17+
"live": "",
18+
"nightly": "chrome opera"
19+
},
20+
"test": "navigator.getUserMedia !== undefined"
21+
},
222
{
323
"desc": "Drag and drop and XHR upload",
424
"url": "dnd-upload",

demos/gum-canvas.html

+36-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,35 @@
11
<title>getUserMedia with canvas effects</title>
22
<style>
3-
#source { -webkit-transform: rotateY(180deg) rotate3d(1, 0, 0, 0deg); display: block; margin: 20px 0; max-width: 100%; }
4-
#strip { display: block; }
3+
#gum {
4+
background: #c00;
5+
color: #fff;
6+
padding: 10px;
7+
}
8+
9+
/* I'm using CSS3 to translate the video on the X axis to give it a mirror effect */
10+
#source {
11+
display: block;
12+
margin: 20px 0;
13+
max-width: 100%;
14+
}
15+
16+
.supported #source { -webkit-transform: rotateY(180deg) rotate3d(1, 0, 0, 0deg);
17+
-o-transform: rotateY(180deg) rotate3d(1, 0, 0, 0deg);
18+
-moz-transform: rotateY(180deg) rotate3d(1, 0, 0, 0deg);
19+
-ms-transform: rotateY(180deg) rotate3d(1, 0, 0, 0deg);
20+
transform: rotateY(180deg) rotate3d(1, 0, 0, 0deg);
21+
}
522
video, canvas { display: none; }
6-
input { width: 360px ;}
7-
output { display: inline-block; width: 16px; height: 16px; background: red; padding: 0; margin: 0;}
23+
input { width: 360px; }
824
</style>
925
<article>
1026
<label for="hue">Colour <input type="range" min="0" max="360" value="0" id="hue"></label> <output id="target"></output>
11-
<video autoplay></video>
27+
<video id="video" muted loop autoplay>
28+
<source src="/assets/remy-and-ellis2.mp4"></source>
29+
<source src="/assets/remy-and-ellis2.webm"></source>
30+
</video>
1231
<canvas id="source"></canvas>
32+
<p id="gum">getUserMeda either not supported or not allowed - so instead here's me and my son headbanging.</p>
1333
</article>
1434
<script>
1535
var video = document.querySelector('video'),
@@ -63,11 +83,11 @@
6383
tr = rgb[0];
6484
tg = rgb[1];
6585
tb = rgb[2];
66-
// console.log(brightness / 256);
6786
};
6887

6988

7089
function init() {
90+
// from HTML5 Doctor article: http://html5doctor.com/getusermedia/
7191
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia;
7292
if (navigator.getUserMedia) {
7393
navigator.getUserMedia('video', successCallback, errorCallback);
@@ -89,12 +109,8 @@
89109
}
90110

91111
video.addEventListener('loadedmetadata', function () {
92-
// output.canvas.width = ;
93112
source.canvas.width = video.videoWidth;
94-
// output.canvas.height =
95113
source.canvas.height = video.videoHeight;
96-
// source.canvas.height = height;
97-
// source.canvas.width = width;
98114
draw();
99115
});
100116

@@ -107,18 +123,17 @@
107123
brightness;
108124

109125
for (; i < pixels.data.length; i += 4) {
110-
// grey = r*.3 + g*.59 + b*.11;
126+
// brightness code from Tab Atkins' canvas demos
111127
brightness = ((3*pixels.data[i]+4*pixels.data[i+1]+pixels.data[i+2])>>>3) / 256;
112128

113129
pixels.data[i] = ((tr * brightness)+0.5)>>0;
114130
pixels.data[i+1] = ((tg * brightness)+0.5)>>0
115131
pixels.data[i+2] = ((tb * brightness)+0.5)>>0
116-
// pixels.data[i+2] = 0;
117132
}
118133
output.putImageData(pixels, 0, 0);
119134
}
120135

121-
// shim layer with setTimeout fallback
136+
// shim layer with setTimeout fallback - from Paul Irish
122137
window.requestAnimFrame = (function(){
123138
return window.requestAnimationFrame ||
124139
window.webkitRequestAnimationFrame ||
@@ -130,8 +145,15 @@
130145
};
131146
})();
132147

148+
var article = video.parentNode,
149+
gum = document.getElementById('gum');
150+
151+
if (navigator.getUserMedia || navigator.webkitGetUserMedia) {
152+
article.removeChild(gum);
153+
article.className = 'supported';
154+
init();
155+
}
133156

134-
init();
135157
</script>
136158
</body>
137159
</html>

demos/gum.html

+26-7
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,39 @@
1-
<title>getUserMedia</title>
1+
<title>getUserMedia streamed to a video element</title>
22
<style>
3-
video {
3+
video {
4+
max-width: 100%;
5+
margin: 0;
6+
}
7+
.supported video {
8+
/* I'm using CSS3 to translate the video on the X axis to give it a mirror effect */
49
-webkit-transform: rotateY(180deg) rotate3d(1, 0, 0, 0deg);
510
-o-transform: rotateY(180deg) rotate3d(1, 0, 0, 0deg);
611
-moz-transform: rotateY(180deg) rotate3d(1, 0, 0, 0deg);
712
-ms-transform: rotateY(180deg) rotate3d(1, 0, 0, 0deg);
813
transform: rotateY(180deg) rotate3d(1, 0, 0, 0deg);
9-
max-width: 100%;
10-
margin: 0;
14+
}
15+
#gum {
16+
background: #c00;
17+
color: #fff;
18+
padding: 10px;
1119
}
1220
</style>
1321
<article>
14-
<video autoplay></video>
22+
<video id="video" muted loop autoplay>
23+
<source src="/assets/remy-and-ellis2.mp4"></source>
24+
<source src="/assets/remy-and-ellis2.webm"></source>
25+
</video>
26+
<p id="gum">getUserMeda either not supported or not allowed - so instead here's me and my son headbanging.</p>
1527
</article>
1628
<script>
17-
var video = document.querySelector('video');
29+
var video = document.getElementById('video'),
30+
article = video.parentNode,
31+
gum = document.getElementById('gum');
1832

1933
function init() {
2034
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia;
2135
if (navigator.getUserMedia) {
36+
// NOTE: at time of writing March 26, 2012, audio isn't working in Chrome
2237
navigator.getUserMedia('video', successCallback, errorCallback);
2338
// Below is the latest syntax. Using the old syntax for the time being for backwards compatibility.
2439
//navigator.getUserMedia({video: true}, successCallback, errorCallback);
@@ -37,5 +52,9 @@
3752
}
3853
}
3954

40-
init();
55+
if (navigator.getUserMedia || navigator.webkitGetUserMedia) {
56+
article.removeChild(gum);
57+
article.className = 'supported';
58+
init();
59+
}
4160
</script>

demos/web-socket.html

-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
'&' : '&amp;'
7373
};
7474

75-
7675
if (window.WebSocket === undefined) {
7776
state.innerHTML = 'Sockets not supported';
7877
state.className = 'fail';

0 commit comments

Comments
 (0)