mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-18 13:42:06 +00:00
feat: add play and pause seperate song controller.
This commit is contained in:
@ -21,7 +21,7 @@ function _registerLocalShortcut(win, shortcut, action) {
|
||||
|
||||
function registerShortcuts(win, options) {
|
||||
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, "MediaNextTrack", next);
|
||||
@ -41,20 +41,21 @@ function registerShortcuts(win, options) {
|
||||
if (is.linux()) {
|
||||
try {
|
||||
const MPRISPlayer = setupMPRIS();
|
||||
player = MPRISPlayer
|
||||
|
||||
MPRISPlayer.on("raise", () => {
|
||||
win.setSkipTaskbar(false);
|
||||
win.show();
|
||||
});
|
||||
MPRISPlayer.on("playPause", () => {
|
||||
console.log("Playpause");
|
||||
})
|
||||
MPRISPlayer.on("play", () => {
|
||||
console.log('Event:', "play", arguments);
|
||||
player.playbackStatus = 'Playing';
|
||||
playPause()
|
||||
play()
|
||||
});
|
||||
MPRISPlayer.on("pause", () => {
|
||||
console.log('Event:', "pause", arguments);
|
||||
player.playbackStatus = 'Paused';
|
||||
playPause()
|
||||
pause()
|
||||
});
|
||||
MPRISPlayer.on("next", () => {
|
||||
next()
|
||||
@ -63,6 +64,8 @@ function registerShortcuts(win, options) {
|
||||
previous()
|
||||
});
|
||||
|
||||
player = MPRISPlayer
|
||||
|
||||
} catch (e) {
|
||||
console.warn("Error in MPRIS", e);
|
||||
}
|
||||
|
||||
@ -15,4 +15,22 @@ module.exports = () => {
|
||||
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();
|
||||
});
|
||||
};
|
||||
|
||||
@ -13,6 +13,8 @@ module.exports = (win) => {
|
||||
previous: () => pressKey(win, "k"),
|
||||
next: () => pressKey(win, "j"),
|
||||
playPause: () => win.webContents.send("playPause"),
|
||||
play: () => win.webContents.send("play"),
|
||||
pause: () => win.webContents.send("pause"),
|
||||
like: () => pressKey(win, "_"),
|
||||
dislike: () => pressKey(win, "+"),
|
||||
go10sBack: () => pressKey(win, "h"),
|
||||
|
||||
Reference in New Issue
Block a user