javascript - Navigator.mediadevices.getUserMedia() 未访问笔记本电脑内置摄像头
问题描述
我正在开发一个用于视频录制的 Web 应用程序。
我已经尝试了下面的代码,但问题是它与外部摄像头一起工作正常,但在具有相同浏览器的笔记本电脑内置摄像头中,它没有给出对象发现错误。
我正在使用 Firefox 60.6.1
if (navigator.mediaDevices.getUserMedia) {
navigator.mediaDevices.getUserMedia(constraints)
.then(function(stream) {
//load the stream in the video variable
video.srcObject = stream;
//load the stream in revokeAccess variable
revokeAccess=stream;
//video playback
video.play();
/*
Optional to avoid the dual audio disturbance. Playback audio is muted
*/
video.muted= true;
if (MediaRecorder.isTypeSupported('video/webm;codecs=vp9')) {
var options = {mimeType: 'video/webm;codecs=vp9'};
console.log("using vp9");
} else if (MediaRecorder.isTypeSupported('video/webm;codecs=h264')) {
var options = {mimeType: 'video/webm;codecs=h264'};
console.log("using h264");
} else if (MediaRecorder.isTypeSupported('video/webm;codecs=vp8')) {
var options = {mimeType: 'video/webm;codecs=vp8',videoBitsPerSecond : 1500000,audioBitsPerSecond : 160000};
console.log("using vp8");
}else{
console.log('isTypeSupported is not supported, using default codecs for browser');
}
//load the stream and type of video in the function
mediaRecorder = new MediaRecorder(stream,options);
//handle the data availability
mediaRecorder.ondataavailable = handleDataAvailable;
//Start the recording
mediaRecorder.start();
alert("Started Recording");
//push the data into chunks(array)
function handleDataAvailable(event) {
if (event.data.size > 0) {
recordedChunks.push(event.data);
console.log(recordedChunks);
} else {
alert(event);
}
}
//disable the Start Recording button
document.getElementById("startRecording").disabled = true;
})
.catch(function(error) {
//handle the device not found exception
alert("Camera not Found !! Please connect camera properly");
console.log(error);
});
}
我希望应用程序能够在每个平台上运行。
解决方案
您好所有开发人员感谢您的支持和快速响应。
我在代码中使用以下适配器添加修复了这些问题。
var getUserMedia = navigator.getUserMedia ||
navigator.mozGetUserMedia ||
navigator.webkitGetUserMedia;
推荐阅读
- php - 查询不显示一个结果
- git - 从 Github 下载压缩文件后没有文件存在
- pyspark - 获取多列的不同值
- datastage - 如何在数据阶段实现 not regexp_like()
- newrelic - New Relic 中的负 NRQL 平均值(diskFreeBytes)
- r - R - BigQuery:curl::curl_fetch_memory(url,handle = handle)中的错误:无法连接到 www.googleapis.com 端口 443:访问错误
- flutter-web - (Flutter) 如何识别用户在我的 ListView 中单击了 PopupMenuItem 的哪个 ListTile?
- node.js - 如何将 userId 与 post 表链接
- wpf - WPF:绑定到字典的每个组合框项目的唯一样式
- reactjs - 偶尔会出现在 useEffect() 中创建清理功能的警告