Created
July 12, 2012 05:30
-
-
Save anantn/3096031 to your computer and use it in GitHub Desktop.
Example getUserMedia Usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html public "✰"> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>getUserMedia Video Example</title> | |
</head> | |
<body> | |
<button type="button" onclick="toggle()"> | |
Toggle Video | |
</button> | |
<br/> | |
<video id="video" width="800" height="600"></video> | |
<script type="application/javascript;version=1.7"> | |
let streaming = false; | |
let video = document.getElementById("video"); | |
function toggle() { | |
if (!streaming) { | |
startVideo(); | |
return; | |
} | |
video.pause(); | |
video.src = null; | |
streaming = false; | |
} | |
function startVideo() { | |
navigator.mozGetUserMedia( | |
{video: true}, | |
function(stream) { | |
video.src = stream; | |
video.play(); | |
streaming = true; | |
}, | |
function(err) { | |
alert("An error occured! " + err); | |
} | |
); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment