Skip to content

Commit

Permalink
Add Now playing notification Fix Sonerezh#370
Browse files Browse the repository at this point in the history
  • Loading branch information
kuroidoruido committed Sep 28, 2019
1 parent e1c0891 commit 2dfcf9e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/webroot/js/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ function Player() {
if(audioElement.src != "") {
audioElement.play();
}
this.notifyNowPlaying();
};
this.playIndex = function(index) {
this.play(playlist.getByIndex(index).id);
Expand Down Expand Up @@ -205,6 +206,19 @@ function Player() {
this.isShuffle = function() {
return shuffle;
};
this.notifyNowPlaying = function() {
if(Notification) {
Notification.requestPermission().then(function(permission) {
if (permission === 'granted') {
const replace = '_65x65' + (retina ? '@2x' : '') + '$1';
new Notification(`Now playing: ${selected.title} (${selected.playtime})`, {
icon: selected.cover.replace(/(\.[a-z0-9]+)/i, replace),
body: `${selected.artist} / ${selected.album}`
});
}
});
}
};
}

function Playlist() {
Expand Down

0 comments on commit 2dfcf9e

Please sign in to comment.