Skip to content

Commit

Permalink
Fix of th-ch#2323
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzheremi2 committed Aug 28, 2024
1 parent e165e64 commit 7b63d2d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/plugins/synced-lyrics/renderer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import type { SyncedLyricsPluginConfig } from '../types';

export let _ytAPI: YoutubePlayer | null = null;

let timeOffset = 0;

export const renderer = createRenderer<{
observerCallback: MutationCallback;
hasAddedEvents: boolean;
Expand Down Expand Up @@ -76,8 +78,8 @@ export const renderer = createRenderer<{
progressCallback(evt: Event) {
switch (evt.type) {
case 'timeupdate': {
const video = evt.target as HTMLVideoElement;
setCurrentTime(video.currentTime * 1000);
const video = evt.target as HTMLVideoElement; // Internally, youtube stiches videos/songs together as one video stream, leading the start of one song (when playing after another song) to have a much bigger current time than 0
setCurrentTime((video.currentTime - timeOffset) * 1000);
break;
}
}
Expand All @@ -87,6 +89,8 @@ export const renderer = createRenderer<{
setConfig(await ctx.getConfig());

ctx.ipc.on('ytmd:update-song-info', async (info: SongInfo) => {
const video = document.querySelector('video');
timeOffset = video!.currentTime;
await makeLyricsRequest(info);
});
},
Expand Down

0 comments on commit 7b63d2d

Please sign in to comment.