From ba7858e3b0c4ecfe82de8a67f63adc6c1be97993 Mon Sep 17 00:00:00 2001 From: ThaUnknown <6506529+ThaUnknown@users.noreply.github.com> Date: Sun, 9 Oct 2022 13:46:32 +0200 Subject: [PATCH] fix: videos with undef duration --- package.json | 2 +- src/renderer/src/lib/Player/Player.svelte | 25 ++++++++++++----------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index af6442c..3535f48 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Miru", - "version": "3.1.16", + "version": "3.1.17", "author": "ThaUnknown_ ", "description": "Stream anime torrents, real-time with no waiting for downloads.", "main": "src/index.js", diff --git a/src/renderer/src/lib/Player/Player.svelte b/src/renderer/src/lib/Player/Player.svelte index 1f45c55..d9ae6e4 100644 --- a/src/renderer/src/lib/Player/Player.svelte +++ b/src/renderer/src/lib/Player/Player.svelte @@ -66,6 +66,7 @@ let volume = localStorage.getItem('volume') || 1 let playbackRate = 1 $: localStorage.setItem('volume', volume || 0) + $: safeduration = (isFinite(duration) ? duration : currentTime) || 0 function checkAudio () { if ('audioTracks' in HTMLVideoElement.prototype && !video.audioTracks.length) { @@ -179,19 +180,19 @@ } let currentTime = 0 - $: progress = currentTime / duration + $: progress = currentTime / safeduration $: targetTime = (!paused && currentTime) || targetTime function handleMouseDown ({ target }) { wasPaused = paused paused = true - targetTime = target.value * duration + targetTime = target.value * safeduration } function handleMouseUp () { paused = wasPaused currentTime = targetTime } function handleProgress ({ target }) { - targetTime = target.value * duration + targetTime = target.value * safeduration } function autoPlay () { @@ -250,8 +251,8 @@ function seek (time) { if (time === 85 && currentTime < 10) { currentTime = currentTime = 90 - } else if (time === 85 && duration - currentTime < 90) { - currentTime = currentTime = duration + } else if (time === 85 && safeduration - currentTime < 90) { + currentTime = currentTime = safeduration } else { currentTime = currentTime += time } @@ -565,9 +566,9 @@ }, 150) } $: navigator.mediaSession?.setPositionState({ - duration: Math.max(0, duration || 0), + duration: Math.max(0, safeduration || 0), playbackRate: 1, - position: Math.max(0, Math.min(duration || 0, currentTime || 0)) + position: Math.max(0, Math.min(safeduration || 0, currentTime || 0)) }) if ('mediaSession' in navigator) { @@ -633,7 +634,7 @@ let hoverOffset = 0 function handleHover ({ offsetX, target }) { hoverOffset = offsetX / target.clientWidth - hoverTime = duration * hoverOffset + hoverTime = safeduration * hoverOffset hover.style.setProperty('left', hoverOffset * 100 + '%') thumbnail = thumbnailData.thumbnails[Math.floor(hoverTime / thumbnailData.interval)] || ' ' } @@ -651,7 +652,7 @@ function initThumbnails () { const height = 200 / (videoWidth / videoHeight) if (!isNaN(height)) { - thumbnailData.interval = duration / 300 < 5 ? 5 : duration / 300 + thumbnailData.interval = safeduration / 300 < 5 ? 5 : safeduration / 300 thumbnailData.canvas.height = height } } @@ -721,8 +722,8 @@ let completed = false function checkCompletion () { if (!completed) { - const fromend = Math.max(180, duration / 10) - if (duration && currentTime && video?.readyState && duration - fromend < currentTime) { + const fromend = Math.max(180, safeduration / 10) + if (safeduration && currentTime && video?.readyState && safeduration - fromend < currentTime) { if (media?.media?.episodes || media?.media?.nextAiringEpisode?.episode) { if (media.media.episodes || media.media.nextAiringEpisode?.episode > media.episode) { completed = true @@ -942,7 +943,7 @@ {muted ? 'volume_off' : 'volume_up'} -
{toTS(targetTime, duration > 3600 ? 2 : 3)} / {toTS(duration - targetTime, duration > 3600 ? 2 : 3)}
+
{toTS(targetTime, safeduration > 3600 ? 2 : 3)} / {toTS(safeduration - targetTime, safeduration > 3600 ? 2 : 3)}
{#if 'audioTracks' in HTMLVideoElement.prototype && video?.audioTracks?.length > 1}