根据当前号码逐个播放声音文件
I understand question similar to this have been asked before, but none of it answer my problem.
I am working on a queue system where customer get ticket from kiosk and wait counter to call their number, for example 1023. I have sound files of each number in .mp3 format. BTW, the project is developed using php.
The two requirements are the sound files must be play according to the number for example if current number is 1023, it need to play 1.mp3, then 0.mp3, etc.
Another problem is these files need to be played one after the previous ends. I managed to do the 1st part but the sounds play together. Please help me, below are some of my code for the 1st part.
soundmanager.inc
public function getSound($in_value)
{
$value = $in_value;
switch ($value){
case "0":
$path = "sounds/0.mp3";
echo "<audio autoplay>";
echo "<source src=".$path." >";
echo "</audio>";
break;
case "1":
$path = "sounds/1.mp3";
echo "<audio autoplay>";
echo "<source src=".$path." >";
echo "</audio>";
break;
case "2":
$path = "sounds/2.mp3";
echo "<audio autoplay>";
echo "<source src=".$path." >";
echo "</audio>";
break;
//and some more
getSound.php
$word = isset($_POST['no']) ? $_POST['no'] : '';
$array = str_split($word);
$one = $array[0];
$two = $array[1];
$three = $array[2];
$four = $array[3];
$um = SoundManager::getInstance();
$um->getSound($one);
$um->getSound($two);
$um->getSound($three);
$um->getSound($four);
我理解之前提出的类似问题,但没有一个能回答我的问题。 p> \ n
我正在建立一个队列系统,客户从自助服务终端获取票证并等待计数器拨打他们的号码,例如1023.我有.mp3格式的每个号码的声音文件。 顺便说一下,这个项目是用php开发的。 p>
这两个要求是声音文件必须根据数字播放,例如当前的数字是1023,需要播放1.mp3, 然后是0.mp3等。 p>
另一个问题是这些文件需要在前一个结束后播放一次。 我设法完成了第一部分,但声音一起播放。 请帮帮我,下面是我的第一部分代码。 p>
soundmanager.inc p>
public function getSound($ in_value)
{
$ value = $ in_value;
开关($ value){
case“0”:
$ path =“sounds / 0.mp3”;
echo“&lt; audio autoplay&gt; “;
echo”&lt; source src =“。$ path。”&gt;“;
echo”&lt; / audio&gt;“;
break;
case”1“:
$ path =”sounds /1.mp3";
echo“&lt; audio autoplay&gt;”;
echo“&lt; source src =”。$ path。“&gt;”;
echo“&lt; / audio&gt;”;
break ;
case“2”:
$ path =“sounds / 2.mp3”;
echo“&lt; audio autoplay&gt;”;
echo“&lt; source src =”。$ path。“&gt;” ;
echo“&lt; / audio&gt;”;
break;
//以及更多
code> pre>
getSound.php p>
\ n
$ word = isset($ _ POST ['no'])? $ _POST ['no']:'';
$ array = str_split($ word);
$ one = $ array [0];
$ two = $ array [1];
$ three = $ array [2];
$ four = $ array [3];
$ um = SoundManager :: getInstance();
$ um-&gt; getSound($ one);
$ um- &gt; getSound($ two);
$ um-&gt; getSound($ 3);
$ um-&gt; getSound($ 4);
code> pre>
div>
Here you go.
var audioFiles = ["http://www.magnac.com/sounds/onlyroadlarge.mp3", "http://www.magnac.com/sounds/paradiserowlarge.mp3", "http://www.magnac.com/sounds/lordslarge.mp3"];
var audio = document.createElement("audio");
var audioIdx = 0;
audio.addEventListener('ended', function () {
audioIdx++;
if (audioIdx >= audioFiles.length) audioIdx = 0;
this.src = audioFiles[audioIdx];
this.play();
});
audio.src = audioFiles[audioIdx];
audio.play();
var i = 0;
var loop = setInterval(function() {
var audio;
switch (dispatch_units[i]) {
case 'ST39':
audio = new Audio('sounds/alert1.mp3');
break;
case 'ALS':
audio = new Audio('sounds/monty_engine.mp3');
break;
case 'ST38':
audio = new Audio('sounds/twotone.mp3');
break;
}
audio.play();
i++;
if(i<=total_units) {
clearInterval(loop);
}
}, 5000);