From 8c5ac17cdfaaf2d4daeafa2ef35d302e6184df7a Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Tue, 23 Nov 2021 18:19:37 +0200 Subject: [PATCH] fix multiple songInfo calls on start --- providers/song-info-front.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/providers/song-info-front.js b/providers/song-info-front.js index 70d478170b..acd41daf93 100644 --- a/providers/song-info-front.js +++ b/providers/song-info-front.js @@ -22,21 +22,22 @@ module.exports = () => { sendSongInfo(); }) - video.addEventListener('pause', e => { - ipcRenderer.send("playPaused", { isPaused: true, elapsedSeconds: Math.floor(e.target.currentTime) }); - }); - - video.addEventListener('playing', e => { - if (e.target.currentTime > 0){ - ipcRenderer.send("playPaused", { isPaused: false, elapsedSeconds: Math.floor(e.target.currentTime) }); - } - }); + for (const status of ['playing', 'pause']) { + video.addEventListener(status, e => { + if (Math.floor(e.target.currentTime) > 0) { + ipcRenderer.send("playPaused", { + isPaused: status === 'pause', + elapsedSeconds: Math.floor(e.target.currentTime) + }); + } + }); + } function sendSongInfo() { const data = apiEvent.detail.getPlayerResponse(); data.videoDetails.elapsedSeconds = Math.floor(video.currentTime); - data.videoDetails.isPaused = video.paused; - ipcRenderer.send("video-src-changed", JSON.stringify(apiEvent.detail.getPlayerResponse())); + data.videoDetails.isPaused = false; + ipcRenderer.send("video-src-changed", JSON.stringify(data)); } }, { once: true, passive: true }); };