Google Chromeでmp3オーディオファイルを読み込もうとしたときに次のエラーが発生しました:Uncaught (in promise) DOMException: Unable to decode audio data
ウェブオーディオAPIオーディオデータをデコードできません
loadSong(url) {
var AudioCtx = new AudioContext();
var request = new XMLHttpRequest();
request.open('GET', url, true);
request.responseType = "arraybuffer";
request.onload = function() {
console.log(request.response);
AudioCtx.decodeAudioData(
request.response,
function (buffer) {
var currentSong = AudioCtx.createBufferSource();
currentSong.buffer = buffer;
currentSong.connect(AudioCtx.destination);
currentSong.start(0);
},
function (e) {
alert("error: " + e.err);
}
);
};
request.send();
}
ここrequest.response
のはconsole.logです:Firefoxので
ArrayBuffer(153) {}
byteLength:0
__proto__:ArrayBuffer
byteLength:0
constructor:ƒ ArrayBuffer()
slice:ƒ slice()
Symbol(Symbol.toStringTag):"ArrayBuffer"
get byteLength:ƒ byteLength()
__proto__:Object
私はエラーThe buffer passed to decodeAudioData contains an unknown type of content.
を得た。ここに私のコードです。 OGGファイルで同じエラーが発生する
詳細情報を提供する必要があります。あなたがデコードしようとしている実際のoggファイルを提供していれば、本当に役に立ちます。 –