我在angular8中构建此应用程序,使用 ng s --open 在localhost中一切正常。一种打开麦克风和流的方法。
但是当我使用 ng buid --prod 并将整个文件夹放在服务器中时,到达该文件夹时,除麦克风一个外,所有其他组件都在工作>
Swal.fire({
allowOutsideClick:false,
text: 'title',
imageUrl: 'assets/img/mic.jpg',
imageWidth: 400,
imageHeight: 200,
confirmButtonText: 'Next',
animation: true,
html:
'<audio controls autoplay>record</audio>',
onBeforeOpen: ()=> {
promise = navigator.mediaDevices.getUserMedia({audio:true});
promise
.then(function(mediaStream) {
const audio = Swal.getContent().querySelector('audio');
audio.srcObject = mediaStream;
audio.play();
}).catch(function(err) {
/* handle the error */
console.log(err.name + "::: " + err.message);
});
}
})
收到的错误:
ERROR TypeError: "Fh.a.getContent(...).querySelector(...) is null"
ERROR Error: "Uncaught (in promise): NotAllowedError: The request is not allowed by the user agent or the platform in the current context."