Skip to content

Instantly share code, notes, and snippets.

@kjunichi
Created May 27, 2014 02:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kjunichi/0e4ce8490138b2d63938 to your computer and use it in GitHub Desktop.
Save kjunichi/0e4ce8490138b2d63938 to your computer and use it in GitHub Desktop.
WebRTCのスクリーンキャプチャーを試した。httpsサーバ立ててそこに置く必要あり。Chromeのみ対応
<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