javascript - 音频 .play 方法应该什么时候开始播放音频?
问题描述
当我运行以下...
<audio preload="auto" id="gameFill">
<source src="sounds/gameAttack.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
...
function sleep(ms) {
date = Date.now();
currentDate = null;
do {
currentDate = Date.now();
} while (currentDate - date < ms);
}
...
document.getElementById("gameFill").play();
console.log("A");
sleep(5000);
console.log("B");
...发生以下情况...
- “A”出现在控制台中。
- 等待 5 秒。
- “B”出现在控制台中。
- 声音播放。
为什么在等待 5 秒之前声音没有开始播放?
谢谢,吉姆
解决方案
推荐阅读
- r - Rvest 抓取从 html_text() 返回的网页内容
- python - 将两个字符串方法合二为一
- node.js - 数据处理完成后Nodejs响应API请求
- android - 在另一个居中的文本视图下方有一个文本视图?
- hadoop - 在 Windows 上的 hive / hadoop 上选择 count(*) 失败
- linux - 在shell脚本中查找数据集之间的持续时间及其平均值
- hibernate - spring boot 多个数据库的通用配置
- python - 为连续事件组创建顺序事件 id
- android - 在 android studio 中无法获取旧的通知数据
- python - 有没有把字典放在字典里面的功能?