Skip to content

Commit

Permalink
Fix time breakage from skipIntroPlugin. (#387)
Browse files Browse the repository at this point in the history
  • Loading branch information
iwalton3 committed Mar 4, 2023
1 parent 9e7c7c2 commit b963836
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions native/skipIntroPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,35 +107,38 @@ class skipIntroPlugin {
}


async function onPlayback(e, player, state) {
function onPlayback(e, player, state) {
if (state.NowPlayingItem) {
await injectSkipIntroHtml();
getIntroTimestamps(state.NowPlayingItem);
}

const onTimeUpdate = () => {
// Check if an introduction sequence was detected for this item.
if (!tvIntro?.Valid) {
return;
}
const onTimeUpdate = async () => {
// Check if an introduction sequence was detected for this item.
if (!tvIntro?.Valid) {
return;
}

const seconds = playbackManager.currentTime(player) / 1000;
const skipIntro = document.querySelector(".skipIntro");
const seconds = playbackManager.currentTime(player) / 1000;

// If the skip prompt should be shown, show it.
if (seconds >= tvIntro.ShowSkipPromptAt && seconds < tvIntro.HideSkipPromptAt) {
skipIntro.classList.remove("hide");
return;
}
await injectSkipIntroHtml(); // I have trust issues
const skipIntro = document.querySelector(".skipIntro");

// If the skip prompt should be shown, show it.
if (seconds >= tvIntro.ShowSkipPromptAt && seconds < tvIntro.HideSkipPromptAt) {
skipIntro.classList.remove("hide");
return;
}

skipIntro.classList.add("hide");
};
skipIntro.classList.add("hide");
};

events.on(player, 'timeupdate', onTimeUpdate);
events.on(player, 'timeupdate', onTimeUpdate);

events.on(player, 'playbackstop', () => {
events.off(player, 'timeupdate', onTimeUpdate);
});
const onPlaybackStop = () => {
events.off(player, 'timeupdate', onTimeUpdate);
events.off(player, 'playbackstop', onPlaybackStop);
};
events.on(player, 'playbackstop', onPlaybackStop);
}
};
events.on(playbackManager, 'playbackstart', onPlayback);

Expand Down

0 comments on commit b963836

Please sign in to comment.