This is my code but it does not play any sound… what is wrong?
IONIC 4
import { Component } from '@angular/core';
import { LocalNotifications } from '@ionic-native/local-notifications/ngx';
import { Storage } from '@ionic/storage';
import { NavController, AlertController, Platform } from '@ionic/angular';
import { ToastController } from '@ionic/angular';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
constructor(
public navController: NavController,
public navCtrl: NavController,
private plt: Platform,
private localNotifications: LocalNotifications,
private alertController: AlertController,
private toastController: ToastController) {
this.localNotifications.on('trigger').subscribe(notification => {
this.presentToast();
});
this.localNotifications.on('yes').subscribe(notification => {
this.presentAlert(notification.data.meetingId);
});
this.localNotifications.on('no').subscribe(notification => {
this.presentAlert(notification.data.meetingId);
});
}
// TRIGGER
async presentToast() {
const toast = await this.toastController.create({
message: 'Stop the Sound!',
duration: 2000
});
toast.present();
}
async presentAlert(test) {
const alert = await this.alertController.create({
header: 'Alert',
subHeader: 'Subtitle',
message: test,
buttons: ['OK']
});
await alert.present();
}
// On load or every check!
scheduleNotification() {
this.localNotifications.schedule({
id: 1,
led: { color: '#FF00FF', on: 500, off: 500 },
title: 'Spela upp Athan - 1',
text: 'Abdelbaset Athan spela upp.',
trigger: {at: new Date(new Date().getTime() + 3000)},
data: { meetingId:"Athan - 1" },
sound: 'file://assets/sms.mp3',
actions: [
{ id: 'yes', title: 'Ok, fortsätt lyssna!' },
{ id: 'no', title: 'Stopa Athan' }
]
});
}
}