您的位置:首页 > 其它

webRTC开启摄像头

2018-01-23 10:12 225 查看
配置htts之后就可以开启webRTC了。

<!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的输出。

这里的id是该媒体流的唯一标识。

音频和视频被放到两个数组中。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: