I have an audio folder with voices / words recorded in wave and I want to run Javascript in different cases. For example: "Error logging in. Please try again". I found some codes on the web but they do not play the audios one by one. Here in Stack I found this code - the user-posted the flash - which apparently comes closer than I need:
function loadPlayer() {
var audioPlayer = new Audio();
audioPlayer.controls="controls";
audioPlayer.addEventListener('ended',nextSong,false);
audioPlayer.addEventListener('error',errorFallback,true);
document.getElementById("player").appendChild(audioPlayer);
nextSong();
}
function nextSong() {
if(urls[next]!=undefined) {
var audioPlayer = document.getElementsByTagName('audio')[0];
if(audioPlayer!=undefined) {
audioPlayer.src=urls[next];
audioPlayer.load();
audioPlayer.play();
next++;
} else {
loadPlayer();
}
} else {
alert('the end!');
}
}
function errorFallback() {
nextSong();
}
function playPause() {
var audioPlayer = document.getElementsByTagName('audio')[0];
if(audioPlayer!=undefined) {
if (audioPlayer.paused) {
audioPlayer.play();
} else {
audioPlayer.pause();
}
} else {
loadPlayer();
}
}
function pickSong(num) {
next = num;
nextSong();
}
var urls = new Array();
urls[0] = 'audio.mp3';
urls[1] = 'audio.mp3';
urls[2] = 'audio.mp3';
urls[3] = 'audio.mp3';
urls[4] = 'audio.mp3';
urls[5] = 'audio.mp3';
urls[6] = 'audio.mp3';
var next = 0;
I want to make it clear that I am doing this just for learning. I graduated recently in Computer Technician for internet and I am loving the area of programming. :)