【问题标题】:Cannot read property of undefined(reading 'getusermedia' ) in AWS EC2无法在 AWS EC2 中读取未定义的属性(正在读取 'getusermedia' )
【发布时间】:2021-10-23 02:18:58
【问题描述】:

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

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); 
  
}

当我在服务器中运行该代码时,它显示“未捕获的类型错误:无法读取未定义的属性(读取 'getUserMedia')”

如果有人以前有过这种情况,请帮我一把!

【问题讨论】:

  • 您是否将其托管在 http 上?在 http 未定义 mediaDevices
  • @preben,当我在 localhost(127.0.0.1) 上运行它时,它在 http 上运行良好,我错了吗?
  • 是的,它适用于本地主机,但不适用于来自 http 的服务器
  • 它在 Https 工作,谢谢

标签: javascript amazon-web-services amazon-ec2


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-11
    • 2022-08-08
    • 2022-07-22
    相关资源
    最近更新 更多