[英]Uncaught (in promise) DOMException: Unable to decode audio data
I'm having an issue with decodeAudioData
method using Web Audio API
to playback in Chrome (it works fine in Firefox)-我在使用
Web Audio API
在 Chrome 中播放的decodeAudioData
方法存在问题(它在 Firefox 中运行良好)-
I am sending the audio buffer recorded by media recorder back from the server.我正在将媒体记录器记录的音频缓冲区从服务器发送回。
Server side服务器端
wss = new WebSocketServer({server: server}, function () {});
wss.on('connection', function connection(ws) {
ws.binaryType = "arraybuffer";
ws.on('message', function incoming(message) {
if ((typeof message) == 'string') {
console.log("string message: ", message);
} else {
console.log("not string: ", message);
ws.send(message);
}
});
});
Client side客户端
window.AudioContext = window.AudioContext||window.webkitAudioContext;
navigator.getUserMedia = (navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia);
var context = new AudioContext();
var mediaRecorder;
var chunks = [];
var startTime = 0;
ws = new WebSocket(url);
ws.binaryType = "arraybuffer";
ws.onmessage = function(message) {
if (message.data instanceof ArrayBuffer) {
context.decodeAudioData(message.data, function(soundBuffer){
playBuffer(soundBuffer);
},function(x) {
console.log("decoding failed", x)
});
} else {
console.log("not arrayBuffer", message.data);
}
};
createMediaRecorder();
function createMediaRecorder() {
if (navigator.getUserMedia) {
console.log('getUserMedia supported.');
var constraints = {
"audio": true
};
var onSuccess = function(stream) {
var options = {
audioBitsPerSecond : 128000,
mimeType : 'audio/webm\;codecs=opus'
};
mediaRecorder = new MediaRecorder(stream, options);
};
var onError = function(err) {
console.log('The following error occured: ' + err);
};
navigator.getUserMedia(constraints, onSuccess, onError);
} else {
alert('getUserMedia not supported on your browser!');
}
}
function playBuffer(buf) {
var source = context.createBufferSource();
source.buffer = buf;
source.connect(context.destination);
if (startTime == 0)
startTime = context.currentTime + 0.1; // add 50ms latency to work well across systems
source.start(startTime);
startTime = startTime + source.buffer.duration;
}
function startRecording() {
mediaRecorder.start();
getRecordedData();
}
function getRecordedData() {
mediaRecorder.ondataavailable = function(e) {
console.log('ondataavailable: ', e.data);
chunks.push(e.data);
};
}
function sendRecordedData() {
var superBuffer = new Blob(chunks, {type: 'audio/ogg'});
ws.send(superBuffer);
}
function stopRecording() {
mediaRecorder.stop();
mediaRecorder.onstop = function(e) {
sendRecordedData();
chunks = [];
};
}
While testing with firefox working fine but with chrome generate the following error:使用 firefox 进行测试时工作正常,但使用 chrome 会生成以下错误:
Uncaught (in promise) DOMException: Unable to decode audio data
Any suggestion will be helpful, thanks in advance.任何建议都会有所帮助,在此先感谢。
I encountered the same error.我遇到了同样的错误。 Updating Chrome did not fix it.
更新 Chrome 并没有修复它。 However, debugging in Firefox instead gave me a much more descriptive error:
然而,在 Firefox 中调试反而给了我一个更具描述性的错误:
The buffer passed to decodeAudioData contains an unknown content type.
Uncaught (in promise) DOMException: MediaDecodeAudioDataUnknownContentType
Uncaught (in promise) DOMException: The given encoding is not supported.
Which by the way was occurring because the .mp3 file I wanted to load wasn't found.顺便说一下,这是因为找不到我想要加载的 .mp3 文件。 So I was making a web request, receiving the 404 HTML page, and trying to load that as an mp3, which failed as an 'unsupported audio format'.
因此,我发出了一个 Web 请求,接收了 404 HTML 页面,并尝试将其加载为 mp3,但由于“不受支持的音频格式”而失败。
I encountered the same issue.我遇到了同样的问题。 Upgrading Chrome to the latest release, eg 85.0.4183, resolved the issue for me.
将 Chrome 升级到最新版本,例如 85.0.4183,为我解决了这个问题。
I Had the same error with createjs (I used to load up the files).我对 createjs 有同样的错误(我曾经加载文件)。 It was integration problem with Internet Download Manager (IDM) ... I've solved it by disabling IDM !
这是与 Internet 下载管理器 (IDM) 的集成问题......我通过禁用 IDM 解决了它!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.