gpt4 book ai didi

javascript - 在不播放音频的情况下触发 onend 音频事件

转载 作者:行者123 更新时间:2023-11-28 00:11:14 29 4
gpt4 key购买 nike

我有多个音频文件需要播放,只有当所有音频都播放完毕后,才会显示下一部分。

我编写的代码会自动触发,无需播放任何音频;我该怎么办?这是我的代码:

<!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 - 在不播放音频的情况下触发 onend 音频事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30855921/

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