无法读取 AWS EC2 中未定义(读取'getusermedia')的属性



我已经部署了一个django应用程序到AWS EC2中,以便从扬声器录制音频。这是我的代码记录音频流;

let log = console.log.bind(console),
id = val => document.getElementById(val),
ul = id('ul'),
gUMbtn = id('gUMbtn'),
start = id('start'),
stop = id('stop'),
stream,
recorder,
counter=1,
chunks,
media;

gUMbtn.onclick = e => {
let mv = id('mediaVideo'),
mediaOptions = {            
audio: {
tag: 'audio',
type: 'audio/wav',
ext: '.wav',
gUM: {audio: true}
}
};
media = mediaOptions.audio;
navigator.mediaDevices.getUserMedia(media.gUM).then(_stream => {
stream = _stream;
id('gUMArea').style.display = 'none';
id('btns').style.display = 'inherit';
start.removeAttribute('disabled');
recorder = new MediaRecorder(stream);
recorder.ondataavailable = e => {
chunks.push(e.data);
if(recorder.state == 'inactive'){

makeLink();
}  
};
log('got media successfully');
}).catch(log);
}
start.onclick = e => {
start.disabled = true;
stop.removeAttribute('disabled');
chunks=[];
recorder.start();
}
stop.onclick = e => {
stop.disabled = true;
recorder.stop();
start.removeAttribute('disabled');
}
function makeLink(){
let blob = new Blob(chunks, {type: media.type })
, url = URL.createObjectURL(blob)
, li = document.createElement('li')
, mt = document.createElement(media.tag)
, hf = document.createElement('a')
;

mt.controls = true;
mt.src = url;
hf.href = url;
hf.download = `${counter}${media.ext}`;
hf.innerHTML = `donwload ${hf.download}`;
li.appendChild(mt);
li.appendChild(hf);
ul.innerHTML = ""; 
ul.appendChild(li); 

}

当我在服务器上运行这段代码时,它说&;Uncaught TypeError: Cannot read properties of undefined (reading 'getUserMedia')&;

如果有人有过这样的经历,请帮帮我!

当我在https上托管应用程序时,它运行得很好。实际上,mediaDevice在http中是未定义的。

相关内容

  • 没有找到相关文章

最新更新