webRTC開啓攝像頭

配置htts以後就能夠開啓webRTC了。javascript

<!DOCTYPE html>
<html>
<head>
    <title>OpenCamera</title>
</head>
<body>
    <video id="video" autoplay></video>
</body>
    <script type="text/javascript">
        var getUserMedia=(navigator.getUserMedia ||navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia);
        getUserMedia.call(navigator,{
            video:true,
            audio:true
        },function(localMediaStream){
            
                var video =document.getElementById('video');
                video.src=window.URL.createObjectURL(localMediaStream);
                video.onloadedmetadata=function(e){
                console.log("Label: "+localMediaStream.id);
                console.log("AudioTracks",localMediaStream.getAudioTracks());
                console.log("VideoTracks ",localMediaStream.getVideoTracks());
            };
        },function(e){console.log("Reeeejected!",e);
    });
    </script>
</html>
View Code

這裏給出了一個簡單的例子。須要用到H5的video標籤。經過webRTC註冊攝像頭和麥克風,生成mediastream而後做爲video的輸出。html

這裏的id是該媒體流的惟一標識。java

音頻和視頻被放到兩個數組中。web

相關文章
相關標籤/搜索