Cordova Local Notification playing local sound for iOS and Android

2.3k views Asked by At

I building an alarm app with phonegap/cordova local notification plugin. Everything is working on the android version except that seem not to be able to play custom sound from my local folder.

This is the location of the sound file in my assets folder

www/sound/whistle.mp3

and this is the javascript code i used in the cordova app for playing the alert sound from the assets folder

window.plugin.notification.local.add({ sound: '/www/sound/whistle.mp3' });

I tried also to play the sound from the resource folder, however i dont know in what folder i am suppose to place the sound file and how to add it to the schedule. This is what i have done so far with it

sound path is resource folder

res/sound/whistle.mp3

and this is the javascript code i used in the cordova app

window.plugin.notification.local.add({ sound: 'android.resource://' + package_name + '/raw/sound/whistle' });

For now i dont know what i am doing wrong or not doing. I will be glad if anyone can help me solve this since it is really eating my brain up. Thank you

1

There are 1 answers

0
Tarlonn On

https://github.com/katzer/cordova-plugin-local-notifications

The usage of sound file is shown in the sample. Simple use

window.plugin.notification.local.add({ sound: 'file://sound/whistle.mp3' });

Since the structure of the data changes, www might not be the root. file:// indicates the root of the app resource in this case.