-
-
Save mganeko/ee1f644b08fdca6970ca to your computer and use it in GitHub Desktop.
WebRTC getUserMedia demo with "Simple Web Server
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
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<title>WebRTC getUserMedia</title> | |
<!-- this is demo for http://www.slideshare.net/mganeko/chromebook-webrtc --> | |
<!-- please install from : https://chrome.google.com/webstore/detail/simple-web-server/gajihfoegjplbobbcnikileolkbgjaaf --> | |
</head> | |
<body> | |
<button type="button" onclick="startVideo();">Start video</button> | |
<button type="button" onclick="stopVideo();">Stop video</button> | |
| |
<br /> | |
<div style="position: relative;"> | |
<video id="local-video" autoplay style="position: absolute; top: 0px; width: 320px; height: 240px; border: 1px solid black;"></video> | |
</div> | |
<script> | |
// ---------------------- video handling ----------------------- | |
var localVideo = document.getElementById('local-video'); | |
var localStream = null; | |
// get the local video up | |
function startVideo() { | |
navigator.webkitGetUserMedia({video: true, audio: true}, successCallback, errorCallback); | |
function successCallback(stream) { | |
localStream = stream; | |
localVideo.src = window.webkitURL.createObjectURL(stream); | |
localVideo.play(); | |
} | |
function errorCallback(error) { | |
console.error('An error occurred: [CODE ' + error.code + ']'); | |
return; | |
} | |
} | |
// stop local video | |
function stopVideo() { | |
localVideo.src = ""; | |
localStream.stop(); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment