gpt4 book ai didi

javascript - 通过 XMLHttpRequest 预加载音频文件

转载 作者:太空宇宙 更新时间:2023-11-04 15:25:20 25 4
gpt4 key购买 nike

我目前正在尝试通过浏览器中的 XMLHttpRequest 预加载 MP3 文件并在音频播放器中播放。直接在播放器中设置时播放音频文件。因此,我在处理响应时一定有错误。

loadAudio : function(playerId, source) {
var player = document.getElementById(playerId);
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
console.log('readyState: ' + request.readyState + ', status: ' + request.status)
if (this.readyState == 4 && this.status == 200) {
console.log(request.getAllResponseHeaders());
var blob = new Blob( [request.response] );
var url = URL.createObjectURL( blob );
player.src = url;
player.addEventListener('loaded', function(e) {
URL.revokeObjectURL(player.src);
});
player.play();
// Typical action to be performed when the document is ready:
}
};
request.open("GET", source, true);
request.send();
}

我收到以下错误消息:

DEMUXER_ERROR_COULD_NOT_OPEN: FFmpegDemuxer: open context failed (code 4)

有谁知道在哪里可以找到错误吗?谢谢您的回答。

最佳答案

您可以尝试将 ajax 请求中的响应类型设置为 blob。

loadAudio : function(playerId, source) {
var player = document.getElementById(playerId);
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
console.log('readyState: ' + request.readyState + ', status: ' + request.status)
if (this.readyState == 4 && this.status == 200) {
var url = URL.createObjectURL( request.response);
player.src = url;
player.addEventListener('loaded', function(e) {
URL.revokeObjectURL(player.src);
});
player.play();
// Typical action to be performed when the document is ready:
}
};
request.open("GET", source, true);
request.responseType = 'blob';
request.send();
}

关于javascript - 通过 XMLHttpRequest 预加载音频文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50986879/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com