Prevent error when video not loaded yet

This commit is contained in:
Ajay Ramachandran
2021-10-02 15:46:33 -04:00
parent 25f78ed55b
commit a88aaf4590

View File

@@ -392,7 +392,8 @@ function durationChangeListener(): void {
} }
function segmentDurationFilter(segment: SponsorTime): boolean { function segmentDurationFilter(segment: SponsorTime): boolean {
return segment.videoDuration === 0 || video.duration === 0 || Math.abs(video.duration - segment.videoDuration) < 2; return segment.videoDuration === 0 || !video
|| video.duration === 0 || Math.abs(video.duration - segment.videoDuration) < 2;
} }
function cancelSponsorSchedule(): void { function cancelSponsorSchedule(): void {
@@ -922,7 +923,7 @@ function updatePreviewBar(): void {
}); });
}); });
previewBar.set(previewBarSegments, video.duration) previewBar.set(previewBarSegments, video?.duration)
if (Config.config.showTimeWithSkips) { if (Config.config.showTimeWithSkips) {
const skippedDuration = utils.getTimestampsDuration(previewBarSegments.map(({segment}) => segment)); const skippedDuration = utils.getTimestampsDuration(previewBarSegments.map(({segment}) => segment));
@@ -1390,7 +1391,7 @@ function getRealCurrentTime(): number {
if (playButtonSVGData === replaceSVGData) { if (playButtonSVGData === replaceSVGData) {
// At the end of the video // At the end of the video
return video.duration; return video?.duration;
} else { } else {
return video.currentTime; return video.currentTime;
} }
@@ -1890,7 +1891,7 @@ function showTimeWithoutSkips(skippedDuration: number): void {
display.appendChild(duration); display.appendChild(duration);
} }
const durationAfterSkips = utils.getFormattedTime(video.duration - skippedDuration) const durationAfterSkips = utils.getFormattedTime(video?.duration - skippedDuration)
duration.innerText = (durationAfterSkips == null || skippedDuration <= 0) ? "" : " (" + durationAfterSkips + ")"; duration.innerText = (durationAfterSkips == null || skippedDuration <= 0) ? "" : " (" + durationAfterSkips + ")";
} }