if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) { navigator.mediaDevices.getUserMedia({ video: true, audio: true }).then(function (stream) { console.log(stream); MediaStreamTrack=typeof stream.stop==='function'?stream:stream.getTracks()[1]; video.src=(window.URL).createObjectURL(stream); video.play(); }).catch(function(err){ console.log(err); });最近想通过浏览器调用摄像头,发现一直失败,后来查了说要在https下面才可以,买一个签名证书又要钱,舍不得,请问自签名证书有用吗?
网友回复
可以
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>HTML5 GetUserMedia Demo</title> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" /> </head> <body> <input type="button" title="开启摄像头" value="开启摄像头"BfwOnclick="getMedia();" /><br /> <video height="120px" autoplay="autoplay"></video><hr /> <input type="button" title="拍照" value="拍照"BfwOnclick="getPhoto();" /><br /> <canvas id="canvas1" height="120px"></canvas><hr /> <input type="button" title="视频" value="视频"BfwOnclick="getVedio();" /><br /> <canvas id="canvas2" height="120px"></canvas> <script type="text/javascript"> var video = document.querySelector('video'); var audio, audioType; var canvas1 = document.getElementById('canvas1'); var context1 = canvas1.getContext('2d'); var canvas2 = document.getElementById('canvas2'); var context2 = canvas2.getContext('2d'); navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia; window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL; var exArray = []; //存储设备源ID MediaStreamTrack.getSources(function (sourceInfos) { for (var i = 0; i != sourceInfos.length; ++i) { var sourceInfo = sourceInfos[i]; //这里会遍历audio,video,所以要加以区分 ...
点击查看剩余70%
腾讯混元模型广场里都是混元模型的垂直小模型,如何api调用?
为啥所有的照片分辨率提升工具都会修改照片上的图案细节?
js如何在浏览器中将webm视频的声音分离为单独音频?
微信小程序如何播放第三方域名url的mp4视频?
ai多模态大模型能实时识别视频中的手语为文字吗?
如何远程调试别人的chrome浏览器获取调试信息?
为啥js打开新网页window.open设置窗口宽高无效?
浏览器中js的navigator.mediaDevices.getDisplayMedia屏幕录像无法录制SpeechSynthesisUtterance产生的说话声音?
js中mediaRecorder如何录制window.speechSynthesis声音音频并下载?
python如何直接获取抖音短视频的音频文件url?