javascript - 无法在“MediaDevices”上执行“getUserMedia”:不支持 getUserMedia
问题描述
尝试解决不和谐插件的问题,不断出现错误“无法在'MediaDevices'上执行'getUserMedia':不支持getUserMedia。”。这是使用它的代码片段:
changeMedia(device=false, changing=false){
const plugin = this;
const change = () => {
plugin.media = null;
plugin.mediaInfo.ready = false;
plugin.mediaInfo.error = false;
navigator.mediaDevices.getUserMedia({audio: (device != false ? device : plugin.settings.devices)}).then(s => {
plugin.media = new MediaRecorder(s);
Logger.log("MediaRecorder started successfully");
plugin.media.addEventListener('dataavailable', e => plugin.onRecordingData(e.data));
plugin.media.addEventListener('start', _ => plugin.onRecordingStateChange(0));
plugin.media.addEventListener('stop', _ => plugin.onRecordingStateChange(1));
plugin.media.addEventListener('pause', _ => plugin.onRecordingStateChange(2));
plugin.media.addEventListener('resume', _ => plugin.onRecordingStateChange(3));
plugin.media.addEventListener('error', error => {
Logger.error('Recording error:', error);
});
plugin.mediaInfo.ready = true;
plugin.mediaInfo.error = false;
if(typeof plugin.buttons == 'object' && plugin.buttons.record instanceof Element)
plugin.buttons.record.disabled = false;
}).catch(err => {
plugin.mediaInfo.ready = false;
plugin.mediaInfo.error = true;
if(typeof plugin.buttons == 'object' &&plugin.buttons.record instanceof Element)
plugin.buttons.record.disabled = true;
Logger.error("Failed to start MediaRecorder:", err.message);
if(!changing){
Logger.log("Changing to the default");
plugin.changeMedia('default', true);
}
});
};
有什么解决办法吗?
解决方案
推荐阅读
- android - 如何将此类的 Intent 传递给活动?
- python - 将向量 w 投影到向量 v 上并绘制垂直线 - 准备 PCA
- android - BottomAppBar 和 FloatingActionButton 应用程序:layout_scrollFlags 行为
- google-bigquery - 如何从 BQ 中的结果集创建分区表
- jquery - 从本地存储 jquery 中检索对象
- scala - 如果集群的一个节点关闭,Kafka Consumer 不会收到消息
- android - 为多个不工作的 React Native 组件提供相同的功能
- swift - Swift 类型别名错误
- javascript - Firebase JavaScript 检索动态创建的子键?
- node.js - Sinon Stub 给出了意外的 UnhandledPromiseRejectionWarning