简体   繁体   中英

Cordova Local Notification playing local sound for iOS and Android

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM