触发音频事件而不播放音频
onended audio event firing without playing the audio
我需要播放多个音频文件,只有当所有音频都完全播放时,下一部分才应该显示。
我编写的代码会自动触发,无需播放任何音频;我应该怎么做?这是我的代码:
<!DOCTYPE html>
<html>
<body>
<p>Press play and wait for the audio to end.</p>
<audio id="myAudio" controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<audio id="myAudio2" controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<section id='asd'>
Hsfdads
</section>
<script>
var e= document.getElementById("asd");
console.log(e.style.display);
e.style.display='none';
</script>
<script>
var count=0;
function IncrementCount() {
count+=1;
console.log(count);
if (count ==2){
var e= document.getElementById("asd");
e.style.display='block';
alert("The audios has ended");
count=0;
}
};
var aud = document.getElementById("myAudio");
aud.onended = IncrementCount()
var aud2 = document.getElementById("myAudio2");
aud2.onended = IncrementCount()
</script>
</body>
</html>
我已经让它工作了。
<!DOCTYPE html>
<html>
<body>
<script>
var count=0;
</script>
<p>Press play and wait for the audio to end.</p>
<audio id="myAudio" onended='IncrementCount()' controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<audio id="myAudio2" controls onended='IncrementCount()'>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<section id='asd'>
Hsfdads
</section>
<script>
var e= document.getElementById("asd");
console.log(e.style.display);
e.style.display='none';
</script>
<script>
function IncrementCount() {
count+=1;
console.log(count);
if (count ==2){
var e= document.getElementById("asd");
e.style.display='block';
alert("The audios has ended");
count=0;}
};
</script>
</body>
</html>
相关文章:
- 动态加载的自定义javascript/jQuery/HTML5音频播放器的问题
- Javascript::通过HTML5音频播放器播放列表播放多个音频文件
- HTML5、CSS3和/或JS中旋转CD上的音频播放器
- 想制作一个基于URL的音频播放器,但Javascript不起作用
- 多个音频播放器和 Web 音频 API
- 创建一个只有播放和暂停的Javascript音频播放列表
- HTML5音频播放器只有在双击后才能在移动浏览器上播放
- 为什么我的代码使用javascript与html5音频播放器可以'Don’我不能做两个或两个以上
- 如何用一个html5音频播放器播放多个音频文件
- 需要帮助修复我的javascript"对于循环“;播放音频播放列表
- JS音频播放器,点击列表项即可播放
- HTML5+Javascript音频在音频播放的特定时间触发事件
- 自动播放音频播放列表SoundManager2 bar ui
- jQuery:支持几乎所有格式的音频播放器
- 制作一个html5音频播放列表,自动播放一首又一首歌曲
- 如何在 javascript 中为推送通知提供音频播放文件路径
- 从我自己的按钮启动音频播放器
- 浏览器内音频播放器如何工作
- 如果未找到动态音频 src 或为 null,请使用 javascript 隐藏 HTML5 音频播放器
- 在HTML音频播放器中切换播放/暂停按钮