i have an array of audio files that i want to play them one by one, unfortunately when i tap play, both play at the same time meaning for loop iterate through both and plays. i tried to add setTimeout to 5 sec. then go to the next audio but nothing worked still i can hear both of them.
all i want to act like normal player playing one audio file at a time and once audio file is finished playing, the for loop goes to the next audio in my array till all are played.
this.songs.loadPlaylistSongs(pid).then((p)=>{
if(p.length > 0){
for(let z=0; z<p.length; z++){
let music = p[z].song;
//now play music..
this.file = new MediaPlugin(music);
this.file.play({ playAudioWhenScreenIsLocked : true });
setTimeout(() => {
this.file.stop();
}, 5000);
}
}
}else{ this.tt("Sorry, Playlist has no songs.."); }
}).catch((err)=>{ this.tt(JSON.stringify(err)); });
Or you can give the constructor a undocumented second parameter that is called when “status changes” (but you will have to find out what is returned to that function when, it corresponds to the mediaStatus callback function the original plugin constructor can have at https://github.com/apache/cordova-plugin-media#media).
Unfortunatelly i have failed to implement this, or maybe the docs are not explanatory enough… i have tried every option available but doesn’t give me an alert when song is finished playing or an error occured, thats why i was trying an alternative for setting timeout. My main intetion is to play the next audio after current playback has finished, the following are source codes to alert if playback is finished or error occured incase you want to try yourself. i tried it on real device.
i trigger play via ion-button with playNow($event)