katzer / cordova-plugin-local-notifications

Cordova Local-Notification Plugin
Apache License 2.0
2.57k stars 1.76k forks source link

Trouble with sounds on iOS and Android #1917

Closed jondspa closed 1 month ago

jondspa commented 4 years ago

WARNING: IF YOU IGNORE THIS TEMPLATE, WE'LL IGNORE YOUR ISSUE. YOU MUST FILL THIS IN!

It's a great plugin, been using for years! Thanks! But having trouble with custom sounds. Just get standard device notification sounds instead of my custom sounds.

Any help would be most appreciated!

Your Environment

Notifications would play a custom sound and not the standard phone notification sound

Actual Behavior

Plays standard phone notification sound

Steps to Reproduce

Android soundFile: `file://assets/ding.mp3' also tried 'res://ding.mp3' also tried 'file:///android_asset/www/assets/ding.mp3'

iOS soundFile = "assets/ding.mp3",

      singleObj = {
                channel: "channel1",
                id: 100 + m,
                text: String(reminders[n][0]),
                priority: 2,
                foreground: true,
                sound: soundFile,

                trigger: {
                    every: {
                        weekday: Number(reminders[n][1][n1]) + 1, // days 1-7
                        hour: Number(reminders[n][2][0]),
                        minute: Number(reminders[n][2][1])
                    },
                    count: 1
                }
            }
GitFr33 commented 4 years ago

I was having a similar problem on newer versions of android. I resolved it by switching to timkellypa's version #1891

jondspa commented 4 years ago

Great, thanks. I'll check it out!

ShakeelBeyondvision commented 3 years ago

I am trying to play sound on local notifications from my downloadable sound files in the readable and writable directory of my app's this.file.documentsDirectory or this.file.dataDirectory. This this.file.externalDataDirectory works fine in android. But this.file.documentsDirectory and this.file.dataDirectory are not working in ios. My code is,

var audioDirectory = this.platform.is("ios") ? this.file.documentsDirectory: this.file.externalDataDirectory;
    cordova.plugins.notification.local.schedule({
      id: 1,
      channel: "channel1",
      title: 'Notification 1',
      text: 'Notification 1',
      foreground: true,
      vibrate: true,
      sound: audioDirectory + "half/sound.mp3"
    })

The file path is correct and works fine with android and also I am playing it in ios with native audio with the same path.