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%
ai能接管电脑手机写作剪辑视频自主运营自媒体账号为用户赚钱吗?
python+qwen的api如何实现类似skills的技能创建与自主调用?
python+openai兼容api如何实现自主调用浏览器搜索登录发布信息?
安卓手机投屏电视视频播放结束如何自动播放下一集?
PaddleOCR-VL-1.5与deepseek ocr2谁更好?
电商系统中优惠券规则引擎与组合优惠如何设计避免在代码中重复使用ifelse?
Grok Imagine Video这个ai能根据用户文本指令编辑视频吗?
Openai的Prism到底是啥?
AgenticVision与DeepSeek-OCR2架构的不同?
主流大模型榜单有哪些?


