简体   繁体   English

自动单击链接以下载用navigator.mediaDevices.getUserMedia录制的mp3文件?

[英]Automatically click a link to download an mp3 file recorded with navigator.mediaDevices.getUserMedia?

My page uses getUserMedia in the same way as a JSFiddle I found, so I will link to it for simplicity's sake: https://jsfiddle.net/sasivarunan/bv55z5fe/ 我的页面以与我发现的JSFiddle相同的方式使用getUserMedia,因此为简单起见,我将链接到它: https ://jsfiddle.net/sasivarunan/bv55z5fe/

I've tried to use this jQuery: 我尝试使用此jQuery:

  $('#audioDownload').click();    

in my stopRecord.onclick function in order to automatically click the link and download the mp3 once the recording stops, but it's not working. 在我的stopRecord.onclick函数中,以便在录制停止后自动单击链接并下载mp3,但它不起作用。 I also tried using 我也尝试使用

  document.getElementById("audioDownload").click();

Use this instead: 使用此代替:

$("#audioDownload").get(0).click();

I have tested it in your code and it works: https://jsfiddle.net/bv55z5fe/97/ 我已经在您的代码中对其进行了测试,并且可以正常工作: https//jsfiddle.net/bv55z5fe/97/

While Yusril's answer wasn't working for me, this addition did solve my problem: 尽管Yusril的答案对我不起作用,但这种添加确实解决了我的问题:

recordedAudio.onloadeddata = e => {
  document.getElementById("audioDownload").click();
}

with recordedAudio being the actual mp3 and audioDownload being the link. 其中recordedAudio是实际的mp3,audioDownload是链接。 This must mean that the mp3 is not ready to be downloaded immediately after the stopRecord button is pressed. 这必须表示在按下stopRecord按钮后,mp3尚未准备好立即下载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM