Created
June 4, 2013 16:07
-
-
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では動作しませんでした。
This file contains hidden or 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
<video id="video" autoplay controls></video> |
This file contains hidden or 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
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); | |
} |
This file contains hidden or 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
body { | |
background: #fdd; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment