@kendam wrote:
I am trying to play multiple audio files with ionic media plugin : https://ionicframework.com/docs/native/media. but I am having a hard time making it work as a playlist without using a timeout function.
Here is what I have tried out
playOne(track: AudioFile): Promise<any> { return new Promise(async resolve =>{ const AudFile = await this.media.create(this.file.externalDataDirectory+track.trackUrl); await resolve(AudFile.play()) }); }
Then to play All , I have this :
async playAll(tracks: AudioFile[]): Promise<any>{ let player = (acc, track:AudioFile) => acc.then(() => this.playOne(track) ); tracks.reduce(player, Promise.resolve()); }
This way they are all playing at the same time.
But If The PlayOne method is wrapped in a timeout function, the interval of the milli seconds set on the timeout exists among the play list, but one does not necessarily finish before the other starts and sometimes it waits for a long time before the subsequent file is plaid.
The timeout implementation looks like this :
playOne(track: AudioFile): Promise<any> { return new Promise(async resolve =>{ setTimeout(async ()=>{ const AudFile = await this.media.create(this.file.externalDataDirectory+track.trackUrl); await resolve(AudFile.play()) },3000) }); }
Any suggestion would be appreciated
Posts: 1
Participants: 1