'how to play music in javascript
Hello there I have a html5 desktop push notification written in javascript and when that notification comes up I want to play a sound affect so that the user knows there is a notification for them to look at
heres my code
function notifyMe() {
if (!("Notification" in window)) {
alert("This browser does not support system notifications");
}
else if (Notification.permission === "granted") {
notify();
}
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
if (permission === "granted") {
notify();
}
});
}
function notify() {
var notification = new Notification('TITLE OF NOTIFICATION', {
icon: 'http://carnes.cc/jsnuggets_avatar.jpg',
body: "Hey! You are on notice!",
});
notification.onclick = function () {
window.open("http://carnes.cc");
};
setTimeout(notification.close.bind(notification), 7000);
}
}
notifyMe();
and heres my mp3 file
alarm.mp3
Solution 1:[1]
You can play a song like that :
var audio = new Audio('alarm.mp3');
audio.play();
Check this related topic
Solution 2:[2]
Call the play from the notify() method:
function notify() {
var notification = new Notification('TITLE OF NOTIFICATION', {
icon: 'http://carnes.cc/jsnuggets_avatar.jpg',
body: "Hey! You are on notice!",
});
notification.onclick = function () {
var audio = new Audio('/pathTo/alarm.mp3');
audio.play();
window.open("http://carnes.cc");
};
setTimeout(notification.close.bind(notification), 7000);
}
Solution 3:[3]
KerasClassifier is migrated from keras.wrappers.scikit_learn to scikeras.wrappers.
You need to use below code to access the KerasClassifier :
!pip install scikeras
from scikeras.wrappers import KerasClassifier
Please check this link for more details.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Pritam Banerjee |
| Solution 3 | TFer2 |
