Javascript loop through array of audio files, playing one after another -


i have array of audio urls want loop through , play 1 after other, little bit of space in-between. i'm using angular2 , typescript.

currently happening plays first track, switches , plays second track, not switch next track continues play second one. never stops playing second track , play each once , stop.

my array of audio urls stored in this.listenservice.messagesrcs so

["http://localhost:8000/5827a34e88554c09a7c0d182", "http://localhost:8000/5827a35088554c09a7c0d183", "http://localhost:8000/5827a35288554c09a7c0d184"] 

and here attempt @ looping through them

loopmessages() {     if (this.listenservice.card && this.listenservice.messagesrcs) {         console.log(this.listenservice.messagesrcs);         let message = new audio();         message.setattribute('src', this.listenservice.messagesrcs[0]);         message.load();         settimeout(function() { message.play(); }, 5000);         if (this.listenservice.messagesrcs.length > 1) {             (let = 1; < this.listenservice.messagesrcs.length; i++) {                 console.log(this.listenservice.messagesrcs.length);                 if (this.listenservice.messagesrcs[i + 1]) {                     message.addeventlistener("ended", () => {                         message.setattribute('src', this.listenservice.messagesrcs[i]);                         console.log(message);                         message.load();                         settimeout(function() { message.play(); }, 3000);                     });                 }             }         }                } } 

suggestions sincerely appreciated!


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -