feat: add play and pause seperate song controller.

This commit is contained in:
Manish
2021-10-13 12:27:13 +05:30
parent 88ee0fb989
commit a76f12c01c
3 changed files with 29 additions and 6 deletions

View File

@ -21,7 +21,7 @@ function _registerLocalShortcut(win, shortcut, action) {
function registerShortcuts(win, options) { function registerShortcuts(win, options) {
const songControls = getSongControls(win); const songControls = getSongControls(win);
const { playPause, next, previous, search } = songControls; const { play, pause, playPause, next, previous, search } = songControls;
_registerGlobalShortcut(win.webContents, "MediaPlayPause", playPause); _registerGlobalShortcut(win.webContents, "MediaPlayPause", playPause);
_registerGlobalShortcut(win.webContents, "MediaNextTrack", next); _registerGlobalShortcut(win.webContents, "MediaNextTrack", next);
@ -41,20 +41,21 @@ function registerShortcuts(win, options) {
if (is.linux()) { if (is.linux()) {
try { try {
const MPRISPlayer = setupMPRIS(); const MPRISPlayer = setupMPRIS();
player = MPRISPlayer
MPRISPlayer.on("raise", () => { MPRISPlayer.on("raise", () => {
win.setSkipTaskbar(false); win.setSkipTaskbar(false);
win.show(); win.show();
}); });
MPRISPlayer.on("playPause", () => {
console.log("Playpause");
})
MPRISPlayer.on("play", () => { MPRISPlayer.on("play", () => {
console.log('Event:', "play", arguments);
player.playbackStatus = 'Playing'; player.playbackStatus = 'Playing';
playPause() play()
}); });
MPRISPlayer.on("pause", () => { MPRISPlayer.on("pause", () => {
console.log('Event:', "pause", arguments);
player.playbackStatus = 'Paused'; player.playbackStatus = 'Paused';
playPause() pause()
}); });
MPRISPlayer.on("next", () => { MPRISPlayer.on("next", () => {
next() next()
@ -63,6 +64,8 @@ function registerShortcuts(win, options) {
previous() previous()
}); });
player = MPRISPlayer
} catch (e) { } catch (e) {
console.warn("Error in MPRIS", e); console.warn("Error in MPRIS", e);
} }

View File

@ -15,4 +15,22 @@ module.exports = () => {
videoStream.pause(); videoStream.pause();
} }
}); });
ipcRenderer.on("play", () => {
if (!videoStream) {
videoStream = document.querySelector(".video-stream");
}
if (videoStream.paused) videoStream.play();
});
ipcRenderer.on("pause", () => {
if (!videoStream) {
videoStream = document.querySelector(".video-stream");
}
videoStream.yns_pause ?
videoStream.yns_pause() :
videoStream.pause();
});
}; };

View File

@ -13,6 +13,8 @@ module.exports = (win) => {
previous: () => pressKey(win, "k"), previous: () => pressKey(win, "k"),
next: () => pressKey(win, "j"), next: () => pressKey(win, "j"),
playPause: () => win.webContents.send("playPause"), playPause: () => win.webContents.send("playPause"),
play: () => win.webContents.send("play"),
pause: () => win.webContents.send("pause"),
like: () => pressKey(win, "_"), like: () => pressKey(win, "_"),
dislike: () => pressKey(win, "+"), dislike: () => pressKey(win, "+"),
go10sBack: () => pressKey(win, "h"), go10sBack: () => pressKey(win, "h"),