Skip to content

Commit

Permalink
fix multiple songInfo calls on start
Browse files Browse the repository at this point in the history
  • Loading branch information
Araxeus committed Nov 23, 2021
1 parent 92452f8 commit 8c5ac17
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions providers/song-info-front.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
};

0 comments on commit 8c5ac17

Please sign in to comment.