简体   繁体   中英

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/

I've tried to use this 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. 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/

While Yusril's answer wasn't working for me, this addition did solve my problem:

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

with recordedAudio being the actual mp3 and audioDownload being the link. This must mean that the mp3 is not ready to be downloaded immediately after the stopRecord button is pressed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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