我正在尝试从服务器读取音频文件并播放html5音频。 我可以使其在localhost中正常运行而没有任何问题。
但是它在网站中实际上并不起作用。
var xhr = new XMLHttpRequest();
xhr.open('POST', './getaudio', true);
xhr.responseType = 'arraybuffer';
xhr.onload = function(e) {
// response is unsigned 8 bit integer
var responseArray = new Uint8Array(this.response);
var blob = new Blob([responseArray], {type : 'audio/ogg'});
var blobUrl = URL.createObjectURL(blob);
source.src = blobUrl;
audio.load(); //call this to just preload the audio without playing
audio.play(); //call this to play the song right away
};
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send('id=' + id1);