我需要在浏览器中添加html5网络音频播放器(带有HTML页面控件)。 怎么做到了?
function loadSound(url) {
var request = new XMLHttpRequest();
request.open('GET', url, true);
request.responseType = 'arraybuffer';
// When loaded decode the data
request.onload = function() {
// decode the data
context.decodeAudioData(request.response, function(buffer) {
// when the audio is decoded play the sound
if (request.response) {
}
playSound(buffer);
}, onError);
}
request.send();
}
loadSound("hello.mp3");
function playSound(buffer) {
sourceNode.buffer = buffer;
sourceNode.start(0);
}