gpt4 book ai didi

javascript - 如何在每个X声音上播放音频?在JavaScript中

转载 作者:行者123 更新时间:2023-12-03 02:28:42 33 4
gpt4 key购买 nike

我试图以这种方式做,但没有用

Javascript:

<script>
document.getElementById('player').play();
x = document.one.numberO.value;
i = 0;
x2 = document.one.intervalO.value;
function out(){
if ((document.one.numberO.value == "")||(document.one.numberO.value < 1)||(document.one.intervalO.value < 5)||(document.one.intervalO.value == ""))
{
alert("error");
}
else{
var intervalID = setInterval(start, x2*1000);
i++;
if (i == x)
{
clearInterval(intervalID);
}
}
}

function start(){
document.getElementById('player').play();
}

和HTML:
<form name="one">
Number <br />
<input type="text" name="numberO"><br />
<br />
Interval <br />
<input type="text" name="intervalO">
</form>
<audio id="player" src="too.mp3"></audio>
<div>
<button onclick="out();">Start</button>
<button onclick="document.getElementById('player').pause()">||</button>
<br>
<br>
<button onclick="document.getElementById('player').volume+=0.1"> +</button>
<button onclick="document.getElementById('player').volume-=0.1"> -</button>
</div>

我需要每X秒钟播放一次声音(我从文本字段中获取值)X2次(也从文本字段中获取)

最佳答案

在这里,您可以:)希望它能对您有所帮助。

function out() {
x = document.getElementById('a').value;
intrvl = setInterval("sound(x)", x*1000);
}
i = 0;
function sound(x)
{
if(x == i)
{
clearInterval(intrvl);
}
i++;

document.getElementById('player').play();
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<input type="text" id="a">
<input type="button" value="sec" id="s" onclick="out()">

<audio id="player" src="http://www.soundjay.com/button/beep-01a.mp3"></audio>

</body>
</html>

关于javascript - 如何在每个X声音上播放音频?在JavaScript中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26318776/

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