js 触摸播放音乐
2022年06月14日 | 分类: js | 评论: 0 | 浏览: 1200
var f = function(){
document.body.removeEventListener('touchstart', f);
var xhr = new XMLHttpRequest();
xhr.open('GET', '/assets/audio/bjmusic.mp3', true);
xhr.responseType = 'arraybuffer';
xhr.onload = function(e) {
var context = new window.AudioContext();
context.decodeAudioData(this.response, function(buffer) {
var source = null;
source = context.createBufferSource();
source.buffer = buffer;
source.loop = true;
source.connect(context.destination);
source.start(0);
}, function(e) {
console.log('Error decoding file', e);
});
};
xhr.send();
}
document.body.addEventListener('touchstart', f);顶一下 ▲()
踩一下 ▼()
发表留言
登录后才能发表留言,立即 登录 或 注册
提交 (Ctrl+Enter)
