let audioCtx = new (window.AudioContext || window.webkitAudioContext)();
let xhr = new XMLHttpRequest();
xhr.open('GET', '请求的音乐地址');
xhr.responseType = 'arraybuffer';
xhr.addEventListener('load', () => {
let playsound = (audioBuffer) => {
// console.log(audioBuffer);
let source = audioCtx.createBufferSource();
source.buffer = audioBuffer;
source.connect(audioCtx.destination);
source.loop = true;
source.start();
};
audioCtx.decodeAudioData(xhr.response, function(data) {
// use the decoded data here
playsound(data);
});
});
xhr.send();
手机端可以自动播放音乐的写法
最新推荐文章于 2023-10-27 16:27:10 发布