webRTC开启摄像头
生活随笔
收集整理的這篇文章主要介紹了
webRTC开启摄像头
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
配置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這里給出了一個(gè)簡單的例子。需要用到H5的video標(biāo)簽。通過webRTC注冊攝像頭和麥克風(fēng),生成mediastream然后作為video的輸出。
這里的id是該媒體流的唯一標(biāo)識。
音頻和視頻被放到兩個(gè)數(shù)組中。
轉(zhuǎn)載于:https://www.cnblogs.com/superxuezhazha/p/8334206.html
總結(jié)
以上是生活随笔為你收集整理的webRTC开启摄像头的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Golang之单元测试
- 下一篇: Jquery_如何扩展方法