gpt4 book ai didi

javascript - JavaScript在Chrome中没有声音/在IE中不倒计时

转载 作者:行者123 更新时间:2023-12-03 01:34:06 25 4
gpt4 key购买 nike

我创建了一个简单的计时器,该计时器不会在IE中倒计时。在Chrome中可以运行,但不能播放声音。.您对它为什么会产生任何建议吗?我使用SharePoint内容编辑器嵌入代码。谢谢!

<Script>
<audio id="audioshort" src="/sites/MTDT/HTML/SiteAssets/Shortbeep.mp3" preload="auto"></audio><script>
<audio id="audiolong" src="/sites/MTDT/HTML/SiteAssets/Longbeep.mp3" preload="auto"></audio><script>
</Script>

<Script>
ProgressCountdown(20, 'pageBeginCountdown', 'pageBeginCountdownText').then(value => alert(`Stream time has ended. Please move to another stream`));

function ProgressCountdown(timeleft, bar, text) {
return new Promise((resolve, reject) => {
var countdownTimer = setInterval(() => {
timeleft--;

document.getElementById(bar).value = 20 - timeleft;
document.getElementById(text).textContent = timeleft;

if (timeleft <= 0) {
clearInterval(countdownTimer);
resolve(true);
location.reload();
}
if (timeleft == 5) {
document.getElementById('audioshort').play();
}
}, 1000);
});
}
</Script>
<div class="row begin-countdown">
<div class="col-md-12 text-center">
<h2>Stream time left</h2>
<progress value="0" max="20" id="pageBeginCountdown"></progress>
<p><centre><span id="pageBeginCountdownText">20 </span> minutes<centre></p>
</div>
</div>

最佳答案

您的音频文件周围有一些奇怪的Script标签。它应显示为:

<audio id="audioshort" src="/sites/MTDT/HTML/SiteAssets/Shortbeep.mp3" preload="auto"></audio>
<audio id="audiolong" src="/sites/MTDT/HTML/SiteAssets/Longbeep.mp3" preload="auto"></audio>

那应该可以解决Chrome上的播放问题。
对于IE的问题,这取决于您使用的版本,但是我想不支持 Promise。有关更多信息,请参见 https://caniuse.com/#feat=promises

关于javascript - JavaScript在Chrome中没有声音/在IE中不倒计时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54984607/

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