Here’s what I did:
Service that handles all the audio bits:
import { Events } from 'ionic-angular';
declare var cordova: any;//necessary for file handling
@Injectable()
export class AudioService {
constructor(
public eventCtrl: Events
){
...
}
onStatusUpdate(status){
this.eventCtrl.publish('audio:stopped',status);
console.log("event thrown");
};
}
And on the page that receives the data:
import { Events } from 'ionic-angular';
@Injectable()
export class AudioPage {
constructor(
public eventCtrl: Events
){
...
this.eventCtrl.subscribe('audio:stopped', status => {
console.log("event catch");
if(status==3 || status==4){
this.pauseAll();
}
});
}
}
But I’m getting this error:
typeError: Cannot read property 'publish' of undefined