android - 如何在钛合金中向通知添加声音

标签 android audio notifications titanium

我以这种方式创建通知:

var notification = Titanium.Android.createNotification({
    contentTitle : 'teste #' + nId,
    contentText : 'Click to return to the application.',
    contentIntent : pending,
    sound : Ti.Filesystem.getResRawDirectory() + 'am.mp3',
});

然后,我调用声音方法,但无法在Android手机上获得声音。我已经将'am.mp3'文件放在资源,资源-> android中,并创建了一个名为资源-> android->原始,资源-> android-> res->原始的文件夹,现在解决方案起作用了。我也尝试过:
sound : "/android/res/raw/am.mp3"

就像我对图像所做的一样

有人知道如何使它工作吗?

最佳答案

要创建原始资源,请将音频文件放在platform/android/res/raw文件夹中,并将其引用为:

notification.sound = Ti.Filesystem.getResRawDirectory() + audioFileName;

声音
要在第一次出现通知时播放声音,请为Notification对象的sound属性分配一个声音文件来播放。将文件放在/platform/android/res/raw/文件夹中。通过使用Ti.Filesystem.getResRawDirectory()方法来引用文件,以检索文件的位置,然后将文件名附加到末尾,例如Ti.Filesystem.getResRawDirectory() + 'sound.wav'

默认情况下,每次应用程序调用notify()方法时,都会播放声音。若要覆盖此行为,请将Titanium.Android.FLAG_ONLY_ALERT_ONCE常量添加到Notification对象的flags属性。
var notification = Titanium.Android.createNotification({
    contentTitle: 'Notification 2',
    contentText : 'Just another notification',
    contentIntent: Ti.Android.createPendingIntent({intent: Ti.Android.createIntent({})}),
    icon: Ti.App.Android.R.drawable.warn,
    number: 5,
    when: new Date().getTime(),
    // Sound file located at /platform/android/res/raw/sound.wav
    sound: Ti.Filesystem.getResRawDirectory() + 'sound.wav',
});

来源12

关于android - 如何在钛合金中向通知添加声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37351754/

相关文章:

java - Java游戏音效无法正常工作

ios - Swift:没有调用didRegisterForRemoteNotificationsWithDeviceToken

ios - 在没有 AppDelegate 的 iOS 中收到推送通知时如何获取通知?

android - 如何通过 xml 为自定义 View 传递重力属性?

android - 在操作栏主页图标上设置 OnClickListener 使图标松开按下状态

android - 需要在Android客户端调用Kurento Media Server opencv插件

php - 插入数据库表时发出通知声音

android - 将参数传递给 gradle Exec 任务

android - 如何使用 SoundPool 同步声音

matlab - Matlab中是否具有读取计算机音频并几乎实时存储数据的功能?