简体   繁体   English

Cordova Local Notification播放iOS和Android的本地声音

[英]Cordova Local Notification playing local sound for iOS and Android

I building an alarm app with phonegap/cordova local notification plugin. 我使用phonegap / cordova本地通知插件构建了一个警报应用程序。 Everything is working on the android version except that seem not to be able to play custom sound from my local folder. 一切都在android版本上正常工作,除了似乎无法播放本地文件夹中的自定义声音。

This is the location of the sound file in my assets folder 这是声音文件在我的资源文件夹中的位置

www/sound/whistle.mp3 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 这是我在cordova应用中使用的javascript代码,用于播放资产文件夹中的警报声音

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 RES /声音/whistle.mp3

and this is the javascript code i used in the cordova app 这是我在cordova应用中使用的javascript代码

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 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' }); window.plugin.notification.local.add({声音:'file://sound/whistle.mp3'});

Since the structure of the data changes, www might not be the root. 由于数据的结构发生变化,因此www可能不是根目录。 file:// indicates the root of the app resource in this case. 在这种情况下,file://指示应用程序资源的根目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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