Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sound does not work in service worker in Chrome desktop push notification

I'm trying to play sound in push notification in Chrome browser when I get notification. And I have already set the browser push notification on my site but it does not play sound. I'm already going through the option for sound but get no sound.

option = {
     'body' : 'This is tst Description',
     'icon' : 'icon.png',
     'silent' : 'false',
     'sound' : 'bell.mp3'
}

If there is any other way to play the sound in the notification, please let me know.

like image 519
Bhavik Hirani Avatar asked Oct 22 '16 08:10

Bhavik Hirani


Video Answer


2 Answers

or you can declare myAudio object globally and use play() funcation after or before notification is popped.

myAudio = new Audio("alert_tone.mp3");

var notification = new Notification("Hi there", options);
myAudio.play();
like image 99
Suraj Verma Avatar answered Sep 20 '22 09:09

Suraj Verma


Currently browsers doesn't support Notification.sound see https://developer.mozilla.org/en/docs/Web/API/notification

like image 43
Alexander Shapoval Avatar answered Sep 19 '22 09:09

Alexander Shapoval