Reputation: 47
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);
Upvotes: 0
Views: 1239
Reputation: 283
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);
Upvotes: 0
Reputation: 516
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();
Upvotes: 1