Created
May 27, 2014 02:01
-
-
Save kjunichi/0e4ce8490138b2d63938 to your computer and use it in GitHub Desktop.
WebRTCのスクリーンキャプチャーを試した。httpsサーバ立ててそこに置く必要あり。Chromeのみ対応
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> | |
<meta charset="UTF-8"> | |
<video id='world' width="256" height="256" autoplay></video> | |
<button onClick="start()">start</button> | |
<button onClick="stop()">stop</button> | |
<script> | |
var video = document.getElementById("world"); | |
var localStream; | |
function start() { | |
if (navigator.webkitGetUserMedia) { | |
navigator.webkitGetUserMedia({ | |
audio: false, | |
video: { | |
mandatory: { | |
chromeMediaSource: 'screen', | |
minWidth: 1280, | |
maxWidth: 2560, | |
minHeight: 720, | |
maxHeight: 1440 | |
} | |
} | |
}, function (stream) { | |
localStream = stream; | |
var url = window.webkitURL.createObjectURL(stream); | |
video.src = url; | |
video.play(); | |
}, function (error) {}); | |
} else if (navigator.mozGetUserMedia) { | |
navigator.mozGetUserMedia({ | |
video: true | |
}, | |
function (stream) { | |
video.mozSrcObject = stream; | |
video.play(); | |
streaming = true; | |
}, | |
function (err) { | |
alert("An error occured! " + err); | |
} | |
); | |
} else if (navigator.getUserMedia) { | |
navigator.getUserMedia("audio, video", success, error); | |
} | |
} | |
function stop() { | |
if (navigator.webkitGetUserMedia) { | |
localStream.stop(); | |
//video.stop(); | |
//video.src = null; | |
} | |
if (video.mozSrcObject) { | |
//video.mozSrcObject.stop(); | |
video.mozSrcObject = null; | |
} | |
} | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment