Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are sounds implemented yet? #9

Closed
adamgins opened this issue Dec 28, 2014 · 57 comments
Closed

Are sounds implemented yet? #9

adamgins opened this issue Dec 28, 2014 · 57 comments

Comments

@adamgins
Copy link
Collaborator

HI,

anything I am missing to get sounds to work?

here's my init:

Push.init({

            bagde: true,
            sound: true,
            alert: true
        });

BTW, they seem to work fine on iOS if I am using one with push simulators.

@raix
Copy link
Collaborator

raix commented Dec 28, 2014

Not sure about push in simulator - it might have quirks - the sound issue not sure - havent used it my self

@raix
Copy link
Collaborator

raix commented Dec 29, 2014

should work in 2.3.0 but QA is needed, havent tested sound at all - but its implemented

@pefi1011
Copy link

Hi @adamgins I get the sound on android when the notification arrives without writing sound:true at all

@adamgins
Copy link
Collaborator Author

@pefi1011 thanks. Yep, that's what I have.
I remember reading somewhere that with Cordova on iOS I think you need to specify the sound file.

If I send the test payload (using one of those APN test apps) it works:

{
    "aps" : {
        "alert" : "You got your emails.",
        "badge" : 9,
        "sound" : "bingbong.aiff"
    },
    "acme1" : "bar",
    "acme2" : 42
}

but not using this package.

@raix
Copy link
Collaborator

raix commented Dec 29, 2014

It should work now

@adamgins
Copy link
Collaborator Author

adamgins commented Jan 2, 2015

Hi, still having an issue with sounds... Do I need to put my own sound file somewhere in the project?

I see code refers to notification.sound not sure what this evaluates to or if I need to pass it as a param

@raix
Copy link
Collaborator

raix commented Jan 3, 2015

@adamgins try the 2.3.3 - I've updated the path to the sound file. It should be placed in the meteor public folder.
Meteor puts the app in sub folder application so its updated now - but I'm not 100% sure it will work, meteor actually runs a small server on the device so we are running at http://meteor.local

If you cant get sound to work we might have to try and use the server prefix instead.

@krishnaff
Copy link

Hello @adamgins Did you get the sound to work?
I tried quite a few combinations including "sound" : "somefile.aiff".
I merely want the default native alert tone to play when the push is delivered to the device. Just "sound": true does not work.

@adamgins
Copy link
Collaborator Author

yep, I have same issue. It works fine on Android but cannot get sound to work on iOS. Been flatout on other stuff to come back and look at it. @raix wondering if it works for you?

@raix
Copy link
Collaborator

raix commented Jan 27, 2015

Havent tested this part fully yet

@hellogerard
Copy link

@insaneinc01, @adamgins, This may be a long shot, but does this work:

sound: 'default'

if in call, or:

"sound": "default"

if in config.

@adamgins
Copy link
Collaborator Author

adamgins commented Feb 6, 2015

It's been a while since I have looked at this issue. Anyone get sounds working on iOS yet?

@krishnaff
Copy link

@hellogerard @adamgins
No luck yet. Tried
sound: 'default'
both in the call and config, does not work.

I'm trying only on iOS though.

@maabed
Copy link

maabed commented Feb 6, 2015

@hellogerard @adamgins

Push.send({
         from: 'Test',
         title: 'Test',
         text:msgText,
         sound: '/audio/mySound.mp3',
         badge: 1,
         query: { }
      });

works fine for me after adding org.apache.cordova.media plugin

@raix
Copy link
Collaborator

raix commented Feb 6, 2015

@maabed sounds cool - If you guys can confirm that adding the cordova.media plugin solves this we should prop. consider making the media plugin a dependency?

@krishnaff
Copy link

@maabed tried your suggestion, but it still doesn't work :( I did add org.apache.cordova.media.
I have placed the mySound.mp3 file in the Public folder. Sorry I might be missing something very obvious here.

@krishnaff
Copy link

ok! I finally got the sounds working. Just the default native iOS push sound, not customized sounds.

config.push.json never worked for me. It always gets stuck on the Meteor splash screen. So I used @spencercarli suggestion here: #21 (comment)

if (Meteor.isServer) {
  Meteor.startup(function () {
    Push.debug = true;

    Push.Configure({
      apn: {
        passphrase: 'test1011',
        certData: Assets.getText('PushChatCert.pem'),
        keyData: Assets.getText('PushChatKey.pem'),
        gateway: 'gateway.sandbox.push.apple.com'
      },
      production: false
    });
  });
} 
if (Meteor.isClient) {
  Meteor.startup(function() {
    Push.Configure({
      "sound": true
    });
    Push.debug = true;
  })
}

And in push.send call:

Push.send({from: 'push',title: 'Congratulations',text: 'You can now Push to this device!', sound: 'blahblah', query: {}})

Note the value - sound: 'someString'.
Thanks @maabed

@raix
Copy link
Collaborator

raix commented Feb 7, 2015

regarding:

config.push.json never worked for me. It always gets stuck on the Meteor splash screen

Have you tried using $ meteor --production?

I've filed an issue on this but they want a replication - I'm not sure I can

@krishnaff
Copy link

Hi @raix ,
--production works! Thanks for that!

Btw, since my requirement is only to trigger the default Push sound on iOS, the org.apache.cordova.media plugin is really not needed.

@raix
Copy link
Collaborator

raix commented Feb 7, 2015

@insaneinc01 super :)

I actually thought the sound was HTML5 why the media plugin is a bit of a surprise.

@adamgins
Copy link
Collaborator Author

adamgins commented Feb 9, 2015

Hi folks, great stuff... just catching up here. So, am I reading correctly:

  1. we don't actually need the plugin?
  2. We just need to add the:
 Push.Configure({
      "sound": true
    });

to the client?
3) sorry a bit confused what's in the sound:<string>? is it just 'default'?

thanks

@adamgins
Copy link
Collaborator Author

adamgins commented Feb 9, 2015

Ah by the way, if I add the Push.Configure above, I get: Uncaught Error: Push.Configure should not be called more than once!

I am only calling it once in the client code. But I am using the config.push.json

@raix
Copy link
Collaborator

raix commented Feb 9, 2015

The config.push.json creates the specific Push.Configure in each environment - so you should only use one of the config methods - The sound should be set true in the config and in the push send you reference the sound file as string

@adamgins
Copy link
Collaborator Author

adamgins commented Feb 9, 2015

thanks… I was just trying that … but seemed to be getting an issue after installing Cordova media plugin.. do I actually need it?

On 9 Feb 2015, at 5:59 pm, Morten N.O. Nørgaard Henriksen notifications@github.com wrote:

The config.push.json creates the specific Push.Configure in each environment - so you should only use one of the config methods - The sound should be set true in the config and in the push send you reference the sound file as string


Reply to this email directly or view it on GitHub.

@raix
Copy link
Collaborator

raix commented Feb 9, 2015

I dont think the media is required - but I'm not sure - playing sound on ios is triggy

@krishnaff
Copy link

@adamgins The Cordova media plugin is not needed if you only need to trigger the default native push sound on iOS.
In the Push.Send call, the "sound": "default" or "sound": "yes" is needed. I guess any string value here will trigger the default push sound.
Push.send({from: 'push',title: 'Congratulations',
text: 'You can now Push to this device!', sound: 'blahblah', query: {}})

@adamgins
Copy link
Collaborator Author

Thanks @insaneinc01 ok sound playing now while app is open only. Is there something else I need to do so it plays if the app is closed?

@adamgins
Copy link
Collaborator Author

adamgins commented Mar 9, 2015

Hi, this started working for whilst the app was closed... not sure if it was an udpate...anyway, closing this. Thanks for all the help folks.

@raix
Copy link
Collaborator

raix commented Nov 17, 2015

I haven't tested sound yet since shifted to the new cordova plugin - please let me know if you find a bug
(I do take pr's :) )

@mvgalle
Copy link

mvgalle commented Nov 24, 2015

Solved! This may be a work around, but it does work and it works consistently. None of the above methods worked for me, however the following does work.

You will want to add a new folder under the following path in your project > .meteor/local/cordova-build/platforms/android/res/ , add a folder called raw . In the raw folder add your sounds.

The resulting folder is the exact location that the sounds are being referenced from in android. To see for yourself, you can run your app on a device and log the errors. Do the following:

  1. Build your application to your phone
  2. in the terminal type: adb logcat >> emulator.log
  3. Send yourself a push notification
  4. Check the log. Notice the following error in the log:
    Failed to open file 'android.resource://com.yourappname/res/raw/filename

--- Indeed the app is trying to reference a file that does not exist. Thats why creating a new directory called raw and placing the file inside it does the job.

*** PLEASE NOTE! IN THE PUSH NOTIFICATION - I ALSO REMOVED THE FILE EXTENSION ***.mp3

Push.send({
from: 'push',
title: title,
text: usernameFrom + ' ' + message,
badge: badge,
query: {
userId: userIdTo
},
sound: 'soundNameWithoutExtension'
});

I hope this helps.

Matt

@Streemo
Copy link

Streemo commented Nov 24, 2015

I'll try this out and let you know if I can replicate the success. It's a
bummer that this kind of stuff is not normalized.
On Nov 24, 2015 2:11 PM, "mvgalle" notifications@github.com wrote:

Solved! This may be a work around, but it does work and it works
consistently. None of the above methods worked for me, however the
following does work.

You will want to add a new folder under the following path in your project

.meteor/local/cordova-build/platforms/android/res/ , add a folder called
raw . In the raw folder add your sounds.

The resulting folder is the exact location that the sounds are being
referenced from in android. To see for yourself, you can run your app on a
device and log the errors. Do the following:

  1. Build your application to your phone
  2. in the terminal type: adb logcat >> emulator.log
  3. Send yourself a push notification
  4. Check the log. Notice the following error in the log:
    Failed to open file 'android.resource://com.yourappname/res/raw/filename

--- Indeed the app is trying to reference a file that does not exist.
Thats why creating a new directory called raw and placing the file inside
it does the job.

*** PLEASE NOTE! IN THE PUSH NOTIFICATION - I ALSO REMOVED THE FILE
EXTENSION ***.mp3

Push.send({
from: 'push',
title: title,
text: usernameFrom + ' ' + message,
badge: badge,
query: {
userId: userIdTo
},
sound: 'soundNameWithoutExtension'
});

I hope this helps.

Matt


Reply to this email directly or view it on GitHub
#9 (comment).

@MichaelJCole
Copy link

@mvgalle brilliant solution!

Here's where it's documented in the cordova plugin

I added this to my build before the meteor command. It may require the app to have already been built once.

mkdir -p .meteor/local/cordova-build/platforms/android/res/raw
cp public/alert.mp3 .meteor/local/cordova-build/platforms/android/res/raw/alert.mp3

I tried naming the file res/raw/alert.mp3.mp3 hoping to call it alert.mp3 in the notification, but that did not work :-/ A unified API would likely either need to add the .mp3 for Android or for iOS.

@1ns1d3r
Copy link

1ns1d3r commented Nov 25, 2015

@mvgalle it's works! thanks

@willemserik
Copy link

i can't get it working to play the default sound on IOS.
in client/main.js i have:
if (Meteor.isClient) {
Meteor.startup(function() {
Push.Configure({
"sound": true
});
Push.debug = true;
})
}

in config.push.json i have:
{
"apn-dev": {
"passphrase": "xxxxxxxxxx",
"key": "key.pem",
"cert": "cert.pem",
"gateway": "gateway.sandbox.push.apple.com"
},
"production": false,
"badge": true,
"sound": true,
"alert": true,
"vibrate": true
}

the alert is working and badge too but the sound is not working

@Streemo
Copy link

Streemo commented Nov 26, 2015

@mvgalle Great! Thanks for sharing, this works. If anyone is still having issues with this problem, here's a summary of what worked for me, from start to finish, using a custom modification of raix:push [1]:

Create myalert.mp3 and myalert.wav.
Load myalert.wav into this package via package.js:

...
api.addAssets('lib/public/myalert.wav','client');
api.export('Push')
...

Next, we need to add myalert.mp3 into a special folder to work with android. see @mvgalle's post

#in your project's root
mkdir .meteor/local/cordova-build/platforms/android/res/raw
cp path/to/myalertmp3 .meteor/local/cordova-build/platforms/android/res/raw/myalert.mp3

Your config.push.json should look like this:

{
  ...
  "sound":true
}

Your calls to Push.send should look like this:

Push.send({
  ...
  apn:{
    //this works because we added 'myalert.wav' as an asset to the custom push package.
    sound: "www/application/packages/yourname_push/lib/public/myalert.wav",
    ...
  },
  gcm: {
    //this will refer to the file we placed in '.meteor/local/.../android/res/raw'
    sound: "myalert",
    ...
  }
})

[1] To create a custom modification of raix:push, use git clone to pipe the source code of raix:push into yourproject/packages/push. Then modify the name in package.js to yourname:push. I did this because I needed to modify some source code of raix:push. If you don't need to modify the source, then you can just put myalert.wav into yourproject/public, and meteor should load it into the www/application/... directory during the build.

@MichaelJCole
Copy link

Clever @Streemo ! Thanks for posting this!

@raix
Copy link
Collaborator

raix commented Nov 28, 2015

nice guys - should we add the solution to the docs or somehow improve the api?

@maciejsaw
Copy link

Is this eventually handled by this package? Perfect solution would be to keep the audio file somewhere and add a filepath to mobile.config so that it's automatically added into res/raw folder when building.

@maciejsaw
Copy link

maciejsaw commented May 1, 2016

The cordova-build-override folder might help http://guide.meteor.com/mobile.html#advanced-build

I can confirm that this solution worked for me on Android.

  1. In root of your project create path /cordova-build-override folder
  2. Place your audio file in a folder structure like this /cordova-build-override/platforms/android/res/raw/sound.mp3
    Don't use special characters and hyphens in sound file name
    screen shot 2016-05-01 at 11 59 59 pm
  3. In config.push.json say "sound": true
    screen shot 2016-05-02 at 12 04 56 am
  4. When sending push say sound: "sound" (sound.mp3 referred WITHOUT extension)
    screen shot 2016-05-01 at 11 59 47 pm

@raix can you add this into the docs and update the example app?

Possible solution for iOS (NOT TESTED):
I assume for iOS you can use similar workflow but place the sound file in public folder and refer the file with full path of cordova build:

Push.send({
  ...
  apn:{
    //this should work because we added audio files in the public folder
    //so this file will be copied to cordova build into the path below
    sound: "www/application/app/sound.wav",
    ...
  },
  gcm: {
    //this will refer to the audio file we placed in /cordova-build-override
    sound: "sound",
    ...
  }
})

@ouya99
Copy link

ouya99 commented May 11, 2016

anyone tested

Possible solution for iOS (NOT TESTED):
I assume for iOS you can use similar workflow but place the sound file in public folder and refer the file with full path of cordova build:

for iOS?

@philipthomasme
Copy link

@java99 Exactly.
For iOS simply place the file in the public folder and refer to it like so:
sound: "www/application/app/sound.wav"

@sahanDissanayake
Copy link

@philipthomasme where do you write this piece of code ?

@maciejsaw
Copy link

@sahanDissanayake I think you specify it in Push.send configuration, see my post above.

@sahanDissanayake
Copy link

yep sweet :) working through it right now.

wasn't 100% sure because you had ... after the sound is defined.. But I will give this a shot

Also I'm thinking from your post that For Android it is mp3 and for IOS it is WAV format ?

Thanks

@maciejsaw
Copy link

I can only confirm that for Android it's MP3. For iOS I didn't implement it yet. But I've seen people using .wav for iOS in the posts above.

@sahanDissanayake
Copy link

sahanDissanayake commented May 24, 2016

@maabed Perfect solution on the top.. Everything is working
So Android sound file is MP3
and IOS uses WAV

( I had the ipad on silent mode.. DUHH!!! ) Thanks

@sahanDissanayake
Copy link

sahanDissanayake commented May 24, 2016

hi @maciejsaw since you are one of the few poeple that got the plugin to work on Android maybe you might have an idea

There are no badge on the icon and also if you send multiple push notifications from the server then one notification on the phone is replaced by the next notification on ANDROID, Which means there is always one ONE notification on tray 😢

raix:push@3.0.0-rc.2

My cordova-plugins

de.appplant.cordova.plugin.local-notification@0.8.4
org.apache.cordova.dialogs@1.2.1
org.apache.cordova.vibration@2.1.1

@maciejsaw
Copy link

I have the same problem of only one notification but I didn't try to solve
it yet.

With the badges I wouldn't worry too much if it doesn't work, android os
doesn't have a consistent way to present badges, only some custom home
screens / launchers have it.

On 00:01, Wed, May 25, 2016 sahanDissanayake notifications@github.com
wrote:

hi @maciejsaw https://github.com/maciejsaw since you are one of the few
poeple that got the plugin to work on Android maybe you might have an idea

There are no badge on the icon and also if you send multiple push
notifications from the server then one notification on the phone is
replaced by the next notification on ANDROID, Which means there is always
one ONE notification on tray 😢

raix:push@3.0.3-rc.4

My cordova-plugins

de.appplant.cordova.plugin.local-notification@0.8.4
org.apache.cordova.dialogs@1.2.1
org.apache.cordova.vibration@2.1.1


You are receiving this because you were mentioned.

Reply to this email directly or view it on GitHub
#9 (comment)

@AshHimself
Copy link

AshHimself commented Jul 29, 2016

For custom sounds you are unable to use MP3 (iOS restriction I believe), you need to use WAV or CAF. If you have an mp3 you can simply run the following to convert your mp3 via the terminal.

afconvert -f caff -d LEI16@44100 -c 1 <<file>>.mp3 <file>>.caf

@mjovkovic
Copy link

The solution that @maciejsaw proposed worked for me. To make it work in iOS I had to add nested iOS configuration found here. If it's set in the root of configuration object as described in the docs, iOS doesn't pick it up.

Push.Configure({
...
      "ios": {
        "sound": true,
        "badge": true,
        "alert": true
      }
});

We're on version 3.0.3-rc.2 of the push plugin, I'm not sure if this issue was addressed in later versions.

@atomoc
Copy link

atomoc commented Sep 21, 2019

Does anyone know why the sounds stopped working according to this scheme?

@atomoc
Copy link

atomoc commented Jan 24, 2020

I figured it out! Need to transfer files from res/raw directory to app/src/main/res/raw

@shivang007
Copy link
Contributor

shivang007 commented Jan 24, 2020

Yes, for meteor 1.8.1 ≥ you need to put your resources in cordova-build-override/platforms/android/app/src/main/res/

@atomoc
Copy link

atomoc commented Jan 24, 2020

now at least everyone can find out)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests