LoginSignup
14
15

More than 5 years have passed since last update.

WebRTCのgetUserMediaでビデオ出力

Posted at

カメラとマイクへのアクセスを許可するとブラウザに表示されます。

サポート状況

  • 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);
}
14
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
15