iam currenlty试图修复此javascript代码,但我似乎无法正确解决它仍然抛出
而且我不明白这是怎么回事,所以如果你们能帮助我,我会很高兴
这是代码
<html>
<head>
<script src="nui://game/ui/jquery.js" type="text/javascript"></script>
<script>
var audioPlayer = null;
window.addEventListener('message', function(event) {
if (event.data.transactionType == "playSound") {
if (audioPlayer != null) {
audioPlayer.pause();
}
audioPlayer = new Audio("./sounds/" + event.data.transactionFile + ".ogg");
audioPlayer.volume = event.data.transactionVolume;
audioPlayer.play();
}
});
</script>
</head>
最佳答案
我自己在播放声音时遇到了这个问题。下面的代码为我修复了它:
var soundPromise = audioPlayer.play();
//If the promise exists
if (soundPromise != undefined) {
soundPromise.then(function(_) {
//Pause and reset the sound
sound.pause();
sound.currentTime = 0;
});
}
让我知道您是否有任何问题!
关于javascript - AbortError:play()请求被调用pause()中断,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53735058/