gpt4 book ai didi

javascript - 加载失败,因为找不到支持的源

转载 作者:行者123 更新时间:2023-12-03 02:28:27 25 4
gpt4 key购买 nike

看着previous answer,我想到了重试播放声音的想法:

soundBG.pause();
soundBG.currentTime = 0;
var soundPromise = soundBG.play();

if (soundPromise !== undefined) {
soundPromise.then(function() {
console.log('Sound!');
}).catch(function(error) {
console.error('Failed to start your sound, retrying.');
setTimeout(function(){
soundEffects();
}, 2000);
});
}

但是它仍然不起作用,并且当声音不起作用时,我不断收到错误消息:

DOMException: Failed to load because no supported source was found



反正有解决办法吗?

最佳答案

我在使用音频类型文件时遇到了相同的错误,并使用了它

var url = document.querySelector('audio').src;
var audio = new Audio();
audio.src = url;
var playPromise = audio.play();
if (playPromise !== undefined) {
playPromise.then(function() {
audio.addEventListener('timeupdate',function() {
console.log(audio.currentTime, audio.duration);
}, true);
}).catch(function(error) {
console.error('Failed to start your sound, retrying.');
});
}

关于javascript - 加载失败,因为找不到支持的源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42649342/

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