826
Views
9
Comments
Solved
Play Sound when Onesignal notificacion received
Question

I need to Play a Sound on a Mobile App when it receives a Onesignal Notification, I tried to use the onesignal audio property but I'm not able to make it work.

So I'm trying to place somewhere in the app a Javascript to play sound but I don't know where the App runs when it's closed, seems that onesignal remains like a service to listen to the notification when received.

Any suggestion?

2017-10-11 04-50-47
ccaceres
Solution

Gonçalo Martins wrote:

ccaceres wrote:

I need to Play a Sound on a Mobile App when it receives a Onesignal Notification, I tried to use the onesignal audio property but I'm not able to make it work.

So I'm trying to place somewhere in the app a Javascript to play sound but I don't know where the App runs when it's closed, seems that onesignal remains like a service to listen to the notification when received.

Any suggestion?

Hi. Were you able to solve this requirement you described? Feel free to share it with the community or on the other hand, tell us if you have some further questions.

Cheers,

GM


Yes, I was able to solve it, what I did was to use the receive notification handler event of the OneSignal plugin, to be able to do this I made the following steps:

  • I added the PushNotification block to the layout.
  • Created a Client Action for the NotificationReceivedEvent
  • In the Client Action I have the following:
  • Now the Plugin Appers on every Screen so I have another Client Action that contains the sound script.
  • The sound Script contains the following:
    var audio = new Audio('/ProyectName/platforms/android/res/raw/beep.mp3');
    audio.play();
  • I made step 4 for each screen in the App and now when the OnseSignal receives a Notification the App plays the Sound.

Now I’m working on applying the Background Mode to avoid on closing the app.

I hope this can be helpful.


2022-11-12 11-28-30
Gonçalo Martins
Staff

Hi.

You can use something like this.

2022-11-12 11-28-30
Gonçalo Martins
Staff

ccaceres wrote:

I need to Play a Sound on a Mobile App when it receives a Onesignal Notification, I tried to use the onesignal audio property but I'm not able to make it work.

So I'm trying to place somewhere in the app a Javascript to play sound but I don't know where the App runs when it's closed, seems that onesignal remains like a service to listen to the notification when received.

Any suggestion?

Hi. Were you able to solve this requirement you described? Feel free to share it with the community or on the other hand, tell us if you have some further questions.

Cheers,

GM


2017-10-11 04-50-47
ccaceres
Solution

Gonçalo Martins wrote:

ccaceres wrote:

I need to Play a Sound on a Mobile App when it receives a Onesignal Notification, I tried to use the onesignal audio property but I'm not able to make it work.

So I'm trying to place somewhere in the app a Javascript to play sound but I don't know where the App runs when it's closed, seems that onesignal remains like a service to listen to the notification when received.

Any suggestion?

Hi. Were you able to solve this requirement you described? Feel free to share it with the community or on the other hand, tell us if you have some further questions.

Cheers,

GM


Yes, I was able to solve it, what I did was to use the receive notification handler event of the OneSignal plugin, to be able to do this I made the following steps:

  • I added the PushNotification block to the layout.
  • Created a Client Action for the NotificationReceivedEvent
  • In the Client Action I have the following:
  • Now the Plugin Appers on every Screen so I have another Client Action that contains the sound script.
  • The sound Script contains the following:
    var audio = new Audio('/ProyectName/platforms/android/res/raw/beep.mp3');
    audio.play();
  • I made step 4 for each screen in the App and now when the OnseSignal receives a Notification the App plays the Sound.

Now I’m working on applying the Background Mode to avoid on closing the app.

I hope this can be helpful.


2022-11-12 11-28-30
Gonçalo Martins
Staff

ccaceres wrote:

Gonçalo Martins wrote:

ccaceres wrote:

I need to Play a Sound on a Mobile App when it receives a Onesignal Notification, I tried to use the onesignal audio property but I'm not able to make it work.

So I'm trying to place somewhere in the app a Javascript to play sound but I don't know where the App runs when it's closed, seems that onesignal remains like a service to listen to the notification when received.

Any suggestion?

Hi. Were you able to solve this requirement you described? Feel free to share it with the community or on the other hand, tell us if you have some further questions.

Cheers,

GM


Yes, I was able to solve it, what I did was to use the receive notification handler event of the OneSignal plugin, to be able to do this I made the following steps:

  • I added the PushNotification block to the layout.
  • Created a Client Action for the NotificationReceivedEvent
  • In the Client Action I have the following:
  • Now the Plugin Appers on every Screen so I have another Client Action that contains the sound script.
  • The sound Script contains the following:
    var audio = new Audio('/ProyectName/platforms/android/res/raw/beep.mp3');
    audio.play();
  • I made step 4 for each screen in the App and now when the OnseSignal receives a Notification the App plays the Sound.

Now I’m working on applying the Background Mode to avoid on closing the app.

I hope this can be helpful.


Great explanation.

Also, I'm glad to see that my post about playing sound was useful since you're using it ;)

Cheers and thank you for sharing this with the community.


2017-10-11 04-50-47
ccaceres

Gonçalo Martins wrote:

ccaceres wrote:

Gonçalo Martins wrote:

ccaceres wrote:

I need to Play a Sound on a Mobile App when it receives a Onesignal Notification, I tried to use the onesignal audio property but I'm not able to make it work.

So I'm trying to place somewhere in the app a Javascript to play sound but I don't know where the App runs when it's closed, seems that onesignal remains like a service to listen to the notification when received.

Any suggestion?

Hi. Were you able to solve this requirement you described? Feel free to share it with the community or on the other hand, tell us if you have some further questions.

Cheers,

GM


Yes, I was able to solve it, what I did was to use the receive notification handler event of the OneSignal plugin, to be able to do this I made the following steps:

  • I added the PushNotification block to the layout.
  • Created a Client Action for the NotificationReceivedEvent
  • In the Client Action I have the following:
  • Now the Plugin Appers on every Screen so I have another Client Action that contains the sound script.
  • The sound Script contains the following:
    var audio = new Audio('/ProyectName/platforms/android/res/raw/beep.mp3');
    audio.play();
  • I made step 4 for each screen in the App and now when the OnseSignal receives a Notification the App plays the Sound.

Now I’m working on applying the Background Mode to avoid on closing the app.

I hope this can be helpful.


Great explanation.

Also, I'm glad to see that my post about playing sound was useful since you're using it ;)

Cheers and thank you for sharing this with the community.


That's right it was very helpful.

Thanks..!!!


2020-01-03 05-37-58
JEYASRI R

ccaceres wrote:

Gonçalo Martins wrote:

ccaceres wrote:

Gonçalo Martins wrote:

ccaceres wrote:

I need to Play a Sound on a Mobile App when it receives a Onesignal Notification, I tried to use the onesignal audio property but I'm not able to make it work.

So I'm trying to place somewhere in the app a Javascript to play sound but I don't know where the App runs when it's closed, seems that onesignal remains like a service to listen to the notification when received.

Any suggestion?

Hi. Were you able to solve this requirement you described? Feel free to share it with the community or on the other hand, tell us if you have some further questions.

Cheers,

GM


Yes, I was able to solve it, what I did was to use the receive notification handler event of the OneSignal plugin, to be able to do this I made the following steps:

  • I added the PushNotification block to the layout.
  • Created a Client Action for the NotificationReceivedEvent
  • In the Client Action I have the following:
  • Now the Plugin Appers on every Screen so I have another Client Action that contains the sound script.
  • The sound Script contains the following:
    var audio = new Audio('/ProyectName/platforms/android/res/raw/beep.mp3');
    audio.play();
  • I made step 4 for each screen in the App and now when the OnseSignal receives a Notification the App plays the Sound.

Now I’m working on applying the Background Mode to avoid on closing the app.

I hope this can be helpful.


Great explanation.

Also, I'm glad to see that my post about playing sound was useful since you're using it ;)

Cheers and thank you for sharing this with the community.


That's right it was very helpful.

Thanks..!!!


Hi,

I have tried the above but I am not receiving any sound effect. Any other way to play sound when the notification received.




Thanks,

Jeyasri


2017-06-06 09-43-03
Frans Moquette

Hi,

We too want to play a sound on a mobile phone when a OneSignal notification is received. I mean, literally, at the moment the notification is received. I have tried the above, but that only has the sound played when the app is already active, which is not a complete solution for what we want.

When I look at the structure of the Notification that is received, under Payload there is a Sound attribute, but how this is to be used is not clear. Also unclear is how to set this attribute from a web application. In the OneSignalAPI there is a SendPushNotificationToDevice action, but no way to set a Sound attribute as far as I can tell.

Anyone have any tips on how to set these attributes and have a sound played on notification received, even when the app is not active?

Thanks!

2021-08-23 23-10-18
Michael Kenji Galicinao

Hi is this resolve already if yes can I ask the approach you did for this one ? Thank you ! 

UserImage.jpg
Tamal Mondal

Dear Community, are you guys able to solve this? If you can share the resolution that would be great help. Thank you.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.