downloadAudio(item) {
const content = item.content.replace('http:','https:');
let ajax = new XMLHttpRequest();
ajax.open('GET', content, true);
ajax.responseType = 'blob';
//ajx.withCredentials = true;//如果跨域
ajax.onload = function (oEvent) {
let response = ajax.response;
let a = document.createElement('a');
a.download = content.includes('.amr') ? +new Date() + '.amr' : +new Date() + '.mp3';
a.style.display = 'none';
let blob = new Blob([response]);
a.href = URL.createObjectURL(blob);
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
};
ajax.send();
},
js下载音频
最新推荐文章于 2025-02-21 21:12:42 发布