From 129ee0199a41a0a4fcd8683212049644ae4acd73 Mon Sep 17 00:00:00 2001 From: Ekene Izukanne Date: Mon, 25 May 2020 14:27:14 +0100 Subject: [PATCH 1/2] add media artist/title in metadata for next song --- renderer/components/Control.jsx | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/renderer/components/Control.jsx b/renderer/components/Control.jsx index a10f860..4b2ab29 100644 --- a/renderer/components/Control.jsx +++ b/renderer/components/Control.jsx @@ -541,15 +541,30 @@ class Control extends React.Component { // If we're at the last song, start afresh // else play next song if (i === songs.length - 1) { - next = songs[0].file + next = { + file: songs[0].file, + title: songs[0].title, + artist: songs[0].artist + } } else if (shuffle) { var rand = this.generateRandomNumber(i, songs.length) - next = songs[rand].file + next = { + file: songs[rand].file, + title: songs[rand].title, + artist: songs[rand].artist + } } else { - next = songs[++i].file + const j = ++i + next = { + file: songs[j].file, + title: songs[j].title, + artist: songs[j].artist + } } const media = { - file: next, + file: next.file, + title: next.title, + artist: next.artist, source: source } dispatch(playMedia(media, getPlayer())) From 480856042dd00ff2dbca8e73534b467b0ba48998 Mon Sep 17 00:00:00 2001 From: Ekene Izukanne Date: Mon, 25 May 2020 14:35:43 +0100 Subject: [PATCH 2/2] support notification on media change --- renderer/actions/index.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/renderer/actions/index.js b/renderer/actions/index.js index 96b7c86..b75689e 100644 --- a/renderer/actions/index.js +++ b/renderer/actions/index.js @@ -1,8 +1,9 @@ import { setPlayer } from "../utils" import C from "./constant" +import { appIcon } from "../assets/staticbase64" const fs = window.require("fs") const path = window.require("path") -const { app, dialog } = window.require("electron").remote +const { app, dialog, Notification, nativeImage } = window.require("electron").remote const mm = window.require("music-metadata") export const requestUpdateLibrary = () => ({ @@ -103,7 +104,10 @@ export function playMedia (media, mediaPlayer) { // resume play if the same media is already in progress and paused if (mediaPlayer.currentTime > 0 && mediaPlayer.paused && !mediaPlayer.ended && media.file === currentMedia) { mediaPlayer.play() - .then(() => dispatch(setCurrentMediaMode("Playing"))) + .then(() => { + NotifyOnMediaChange(media.artist, media.title) + return dispatch(setCurrentMediaMode("Playing")) + }) .catch(() => dispatch(setCurrentMediaMode("Paused"))) } else { // start a fresh play @@ -112,6 +116,18 @@ export function playMedia (media, mediaPlayer) { } } +function NotifyOnMediaChange (artist, title) { + if (artist && title && Notification.isSupported()) { + const image = nativeImage.createFromDataURL(`data:image/png;base64,${appIcon}`) + const notification = new Notification({ + title: title, + body: `by ${artist}`, + icon: image + }) + notification.show() + } +} + function fetchMediaBuffer (url, loadMedia) { if ((url.startsWith("https://") || url.startsWith("http://")) && !navigator.onLine) { const title = "Network error" @@ -169,6 +185,7 @@ function setupMediaSrc (media, mediaPlayer) { mediaSrc.endOfStream() mediaPlayer.play() .then(() => { + NotifyOnMediaChange(media.artist, media.title) // dispatch(updateMediaInfo(url)) dispatch(setCurrentMediaMode("Playing")) })