Hello, I succesfully implemented an audio service to handle playing of several concatenated audio files using @ionic-native/media plugin and it’s working fine on Browser when checked on Mac/Chrome. However on iOS/Chrome the first file in the playlist is played but subsequent files aren’t. I did a lot of research but I get no error or info… on iOS the second instance of the mediaObject just does not get played, and I made sure that the code gets executed until the relevant line (this.mediaObject.play() for that instance
This is my audio service:
import {Injectable} from '@angular/core';
import {Media, MediaObject} from "@ionic-native/media";
@Injectable()
export class AudioService {
mediaObject: MediaObject;
playlist: Array<string> = [];
counter:number = 0;
constructor(
private media: Media
) {
}
preparePlayAudio(src: string) {
if (typeof this.mediaObject !== 'undefined') {
this.mediaObject.pause();
this.mediaObject.release();
this.mediaObject = undefined;
}
this.mediaObject = this.media.create(src);
this.playAudio();
}
next() {
this.counter += 1;
if (typeof this.playlist[this.counter] !== 'undefined') {
this.preparePlayAudio(this.playlist[this.counter]);
}
}
playAudio() {
this.mediaObject.play();
this.mediaObject.onStatusUpdate.subscribe(status =>
{
if (status.toString()=="1") { //player start
}
if (status.toString()=="4") { // player end running
this.next()
}
});
}
play(playlist: string[]): void {
this.counter = 0;
this.playlist = playlist;
this.preparePlayAudio(playlist[this.counter]);
}
}
And I call it by
audioService.play(['audio1.mp3', 'audio2.mp3']);
VERSIONS
Ionic Version 3.9.2
Ionic Native Media: 4.7.0