Skip to content

Instantly share code, notes, and snippets.

@wataru218
Created June 4, 2013 16:07
Show Gist options
  • Save wataru218/5707187 to your computer and use it in GitHub Desktop.
Save wataru218/5707187 to your computer and use it in GitHub Desktop.
A CodePen by iw3. WebRTCのgetUserMediaでビデオ出力 - カメラとマイクへのアクセスを許可するとブラウザに表示されます。 - サポート状況 Google Chrome 27、Firefox 21で動作しました。 Opera 12では映像のみ出力され、音声は出力されませんでした。 Internet Explorer、Safariでは動作しませんでした。
<video id="video" autoplay controls></video>
navigator.getMedia = (
navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia
);
if (navigator.getMedia) {
var prop = {
video: true,
audio: true,
toString: function() {
return 'video, audio';
}
};
navigator.getMedia(
prop,
onStream,
onStreamFailed
);
} else {
alert('エラー: getUserMediaがサポートされていません');
}
function onStream(stream) {
if (!window.URL) {
window.URL = {};
window.URL.createObjectURL = function(obj) { return obj; };
}
var video = document.getElementById('video');
video.src = window.URL.createObjectURL(stream);
}
function onStreamFailed(err) {
console.error('エラー: ' + err);
}
body {
background: #fdd;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment