Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 开始在Web上使用音频API:代码在桌面浏览器中工作,但在移动浏览器中不工作_Javascript_Dom Events_Audio Streaming_Getusermedia_Ws - Fatal编程技术网

Javascript 开始在Web上使用音频API:代码在桌面浏览器中工作,但在移动浏览器中不工作

Javascript 开始在Web上使用音频API:代码在桌面浏览器中工作,但在移动浏览器中不工作,javascript,dom-events,audio-streaming,getusermedia,ws,Javascript,Dom Events,Audio Streaming,Getusermedia,Ws,下面给出的代码用于从浏览器录制音频并同时播放。我的问题是,这段代码在桌面浏览器上运行,但在两个最新版本的平台上都不能在使用Chrome浏览器的移动浏览器上运行。有人能帮我吗 <audio id="player" controls></audio> <script> const player = document.getElementById('player'); const handleSuccess = function(stream) {

下面给出的代码用于从浏览器录制音频并同时播放。我的问题是,这段代码在桌面浏览器上运行,但在两个最新版本的平台上都不能在使用Chrome浏览器的移动浏览器上运行。有人能帮我吗

<audio id="player" controls></audio>
<script>
  const player = document.getElementById('player');

  const handleSuccess = function(stream) {

    if (window.URL) {
      player.srcObject = stream;
    } else {
      player.src = stream;
    }
  };

  navigator.mediaDevices.getUserMedia({ audio: true, video: false })
      .then(handleSuccess);
</script>

常量player=document.getElementById('player');
const handleSuccess=函数(流){
if(window.URL){
player.srcObject=流;
}否则{
player.src=流;
}
};
navigator.mediaDevices.getUserMedia({audio:true,video:false})
.然后(顺利);

navigator.mediaDevices.getUserMedia在移动浏览器中没有SSL将无法工作,因此我已经在本地主机上安装了SSL,现在它可以工作了。

您能给我更多关于源代码的描述吗,我将帮助您。它必须由用户事件(如单击)启动。另外,让它跨平台可靠工作也很困难,请准备好卷起袖子。@Dipakchavda感谢您的帮助,但我得到了答案,事实上,如果移动浏览器中没有ssl,navigator将无法工作。我在本地主机上安装了ssl,现在它可以工作了。事实上,它在桌面浏览器上也不能工作。很高兴你找到了解决办法!