|
31 | 31 | <canvas id="source"></canvas>
|
32 | 32 | <p id="gum">getUserMeda either not supported or not allowed - so instead here's me and my son headbanging.</p>
|
33 | 33 | </article>
|
| 34 | +<script src="/js/gum.js"></script> |
34 | 35 | <script>
|
35 |
| -var video = document.querySelector('video'), |
36 |
| - source = document.getElementById('source').getContext('2d'), |
| 36 | +var source = document.getElementById('source').getContext('2d'), |
37 | 37 | output = source, //document.getElementById('output').getContext('2d'),
|
38 | 38 | slider = document.getElementById('hue'),
|
39 | 39 | target = document.getElementById('target'),
|
|
85 | 85 | tb = rgb[2];
|
86 | 86 | };
|
87 | 87 |
|
88 |
| -function successCallback(stream) { |
89 |
| - window.stream = stream; |
90 |
| - if (window.webkitURL) { |
91 |
| - video.src = window.webkitURL.createObjectURL(stream); |
92 |
| - } else { |
93 |
| - video.src = stream; |
94 |
| - } |
95 |
| - video.play(); |
96 |
| -} |
97 |
| - |
98 |
| -function errorCallback(error) { |
99 |
| - console.error('An error occurred: [CODE ' + error.code + ']'); |
100 |
| - return; |
101 |
| -} |
102 |
| - |
103 |
| -function init() { |
104 |
| - // from HTML5 Doctor article: http://html5doctor.com/getusermedia/ |
105 |
| - navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia; |
106 |
| - if (navigator.getUserMedia) { |
107 |
| - navigator.getUserMedia({ video: true }, successCallback, errorCallback); |
108 |
| - } |
109 |
| -} |
110 |
| - |
| 88 | +// note: video is defined in gum.js |
111 | 89 | video.addEventListener('loadedmetadata', function () {
|
112 |
| - source.canvas.width = video.videoWidth; |
113 |
| - source.canvas.height = video.videoHeight; |
| 90 | + // due to bug in Chrome: http://crbug.com/168700 |
| 91 | + if (video.videoWidth) { |
| 92 | + source.canvas.width = video.videoWidth; |
| 93 | + source.canvas.height = video.videoHeight; |
| 94 | + } |
114 | 95 | draw();
|
115 | 96 | });
|
116 | 97 |
|
|
148 | 129 | var article = video.parentNode,
|
149 | 130 | gum = document.getElementById('gum');
|
150 | 131 |
|
151 |
| -if (navigator.getUserMedia || navigator.webkitGetUserMedia) { |
| 132 | +if (navigator.getUserMedia) { |
152 | 133 | article.removeChild(gum);
|
153 | 134 | article.className = 'supported';
|
154 |
| - init(); |
155 | 135 | }
|
156 | 136 |
|
157 | 137 | </script>
|
|
0 commit comments