MediaPlugin plays audio parallely


#1

A Ionic2 newbie, so I could be doing things wrong. I’m trying to use the native MediaPlugin for Ionic 2.
And I’m loading the audio from the user’s directory by reading files, using the File native plugin and passing their nativeURL as the src for the plugin.

Below is the code for (click) on song selection in list of UI:

if(this.songPlaying)
{
console.log(“Stopping and releasing”);
this.player.stop();
this.player.release();
}
console.log(“Playing new song”);
this.player = new MediaPlugin(selectedSong.src);
this.player.init.then(() => {
console.log(‘Playback Finished’);
}, (err) => {
console.log('somthing went wrong! error code: ’ + err.code + ’ message: ’ + err.message);
});
this.player.play();

Works great for the first click(URI of the first song), loads the song and plays it.

However on the second click(URI of the second song), loads the song and plays it, while the first one is still playing (Mild disturbance in between which I think is because of the second song loading ).

I also tried using the NativeAudio plugin in kinda the same way of implementation, didn’t work.

A side note, the console.log(“Stopping and releasing”); or console.log(“Playing new song”); does not give me an output on the console.