html5demos/demos/gum.html

66 lines
2.2 KiB
HTML
Raw Normal View History

2012-03-26 18:39:59 +02:00
<title>getUserMedia streamed to a video element</title>
2012-03-24 11:13:41 +01:00
<style>
2012-11-01 18:04:09 +01:00
audio, video {
2012-03-26 18:39:59 +02:00
max-width: 100%;
margin: 0;
}
2012-11-01 18:04:09 +01:00
.supported video,
.supported audio {
2012-03-26 18:39:59 +02:00
/* I'm using CSS3 to translate the video on the X axis to give it a mirror effect */
2012-03-24 11:13:41 +01:00
-webkit-transform: rotateY(180deg) rotate3d(1, 0, 0, 0deg);
-o-transform: rotateY(180deg) rotate3d(1, 0, 0, 0deg);
-moz-transform: rotateY(180deg) rotate3d(1, 0, 0, 0deg);
-ms-transform: rotateY(180deg) rotate3d(1, 0, 0, 0deg);
transform: rotateY(180deg) rotate3d(1, 0, 0, 0deg);
2012-03-26 18:39:59 +02:00
}
#gum {
background: #c00;
color: #fff;
padding: 10px;
2012-03-24 11:13:41 +01:00
}
</style>
<article>
2012-03-26 18:39:59 +02:00
<video id="video" muted loop autoplay>
<source src="/assets/remy-and-ellis2.mp4"></source>
<source src="/assets/remy-and-ellis2.webm"></source>
</video>
<p id="gum">getUserMeda either not supported or not allowed - so instead here's me and my son headbanging.</p>
2012-03-24 11:13:41 +01:00
</article>
<script>
2012-03-26 18:39:59 +02:00
var video = document.getElementById('video'),
article = video.parentNode,
gum = document.getElementById('gum');
2012-03-24 11:13:41 +01:00
function init() {
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
2012-03-24 11:13:41 +01:00
if (navigator.getUserMedia) {
2012-03-26 18:39:59 +02:00
// NOTE: at time of writing March 26, 2012, audio isn't working in Chrome
2012-11-01 18:04:09 +01:00
// navigator.getUserMedia('audio,video', successCallback, errorCallback);
2012-03-24 11:13:41 +01:00
// Below is the latest syntax. Using the old syntax for the time being for backwards compatibility.
2012-11-01 18:04:09 +01:00
navigator.getUserMedia({video: true, audio: true }, successCallback, errorCallback);
2012-03-24 11:13:41 +01:00
function successCallback(stream) {
window.stream = stream;
if ('mozSrcObject' in video)
video.mozSrcObject = stream;
} else if (window.webkitURL) {
2012-03-24 11:13:41 +01:00
video.src = window.webkitURL.createObjectURL(stream);
2012-11-01 18:04:09 +01:00
// document.querySelector('audio').src = window.webkitURL.createObjectURL(stream);
2012-03-24 11:13:41 +01:00
} else {
video.src = stream;
}
}
function errorCallback(error) {
console.error('An error occurred: [CODE ' + error.code + ']');
return;
}
}
}
if (navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia) {
2012-03-26 18:39:59 +02:00
article.removeChild(gum);
article.className = 'supported';
init();
}
</script>