According to usage guide of cordova-plugin-media says you can trigger action after playback has finished…
Unfortunately, i have tried every option available but doesn’t give me an alert when audio is done playing or an error occured, in my case, i want to play another audio as soon the current audio is done playing. I ran this on device… Please tell me where i am doing wrong…
i trigger play via ion-button with playNow($event)
import { Platform, AlertController } from 'ionic-angular';
import { MediaPlugin } from 'ionic-native';
@Component({
selector: 'page-play',
templateUrl: 'play.html'
})
export class PlayPage {
constructor(public platform:Platform, public alertCtrl:AlertController) {}
playNow(){
this.platform.ready().then(() => {
const onStatusUpdate = (status) => console.log(status);
const file = new MediaPlugin('path/to/file.mp3', onStatusUpdate);
file.init.then(() => {
//show alert playback finished..
let alert = this.alertCtrl.create({
title: 'Info',
subTitle: 'Playback Finished',
buttons: ['Ok']
});
alert.present();
}, (err) => {
//show alert on error..
let alert = this.alertCtrl.create({
title: 'Info',
subTitle: 'Error Playing Audio',
buttons: ['Ok']
});
alert.present();
});
file.play();
});
}
}
Thank you so much.