fix: videos with undef duration

This commit is contained in:
ThaUnknown 2022-10-09 13:46:32 +02:00
parent f6e92879ba
commit ba7858e3b0
2 changed files with 14 additions and 13 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "Miru", "name": "Miru",
"version": "3.1.16", "version": "3.1.17",
"author": "ThaUnknown_ <ThaUnknown@users.noreply.github.com>", "author": "ThaUnknown_ <ThaUnknown@users.noreply.github.com>",
"description": "Stream anime torrents, real-time with no waiting for downloads.", "description": "Stream anime torrents, real-time with no waiting for downloads.",
"main": "src/index.js", "main": "src/index.js",

View file

@ -66,6 +66,7 @@
let volume = localStorage.getItem('volume') || 1 let volume = localStorage.getItem('volume') || 1
let playbackRate = 1 let playbackRate = 1
$: localStorage.setItem('volume', volume || 0) $: localStorage.setItem('volume', volume || 0)
$: safeduration = (isFinite(duration) ? duration : currentTime) || 0
function checkAudio () { function checkAudio () {
if ('audioTracks' in HTMLVideoElement.prototype && !video.audioTracks.length) { if ('audioTracks' in HTMLVideoElement.prototype && !video.audioTracks.length) {
@ -179,19 +180,19 @@
} }
let currentTime = 0 let currentTime = 0
$: progress = currentTime / duration $: progress = currentTime / safeduration
$: targetTime = (!paused && currentTime) || targetTime $: targetTime = (!paused && currentTime) || targetTime
function handleMouseDown ({ target }) { function handleMouseDown ({ target }) {
wasPaused = paused wasPaused = paused
paused = true paused = true
targetTime = target.value * duration targetTime = target.value * safeduration
} }
function handleMouseUp () { function handleMouseUp () {
paused = wasPaused paused = wasPaused
currentTime = targetTime currentTime = targetTime
} }
function handleProgress ({ target }) { function handleProgress ({ target }) {
targetTime = target.value * duration targetTime = target.value * safeduration
} }
function autoPlay () { function autoPlay () {
@ -250,8 +251,8 @@
function seek (time) { function seek (time) {
if (time === 85 && currentTime < 10) { if (time === 85 && currentTime < 10) {
currentTime = currentTime = 90 currentTime = currentTime = 90
} else if (time === 85 && duration - currentTime < 90) { } else if (time === 85 && safeduration - currentTime < 90) {
currentTime = currentTime = duration currentTime = currentTime = safeduration
} else { } else {
currentTime = currentTime += time currentTime = currentTime += time
} }
@ -565,9 +566,9 @@
}, 150) }, 150)
} }
$: navigator.mediaSession?.setPositionState({ $: navigator.mediaSession?.setPositionState({
duration: Math.max(0, duration || 0), duration: Math.max(0, safeduration || 0),
playbackRate: 1, 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) { if ('mediaSession' in navigator) {
@ -633,7 +634,7 @@
let hoverOffset = 0 let hoverOffset = 0
function handleHover ({ offsetX, target }) { function handleHover ({ offsetX, target }) {
hoverOffset = offsetX / target.clientWidth hoverOffset = offsetX / target.clientWidth
hoverTime = duration * hoverOffset hoverTime = safeduration * hoverOffset
hover.style.setProperty('left', hoverOffset * 100 + '%') hover.style.setProperty('left', hoverOffset * 100 + '%')
thumbnail = thumbnailData.thumbnails[Math.floor(hoverTime / thumbnailData.interval)] || ' ' thumbnail = thumbnailData.thumbnails[Math.floor(hoverTime / thumbnailData.interval)] || ' '
} }
@ -651,7 +652,7 @@
function initThumbnails () { function initThumbnails () {
const height = 200 / (videoWidth / videoHeight) const height = 200 / (videoWidth / videoHeight)
if (!isNaN(height)) { if (!isNaN(height)) {
thumbnailData.interval = duration / 300 < 5 ? 5 : duration / 300 thumbnailData.interval = safeduration / 300 < 5 ? 5 : safeduration / 300
thumbnailData.canvas.height = height thumbnailData.canvas.height = height
} }
} }
@ -721,8 +722,8 @@
let completed = false let completed = false
function checkCompletion () { function checkCompletion () {
if (!completed) { if (!completed) {
const fromend = Math.max(180, duration / 10) const fromend = Math.max(180, safeduration / 10)
if (duration && currentTime && video?.readyState && duration - fromend < currentTime) { if (safeduration && currentTime && video?.readyState && safeduration - fromend < currentTime) {
if (media?.media?.episodes || media?.media?.nextAiringEpisode?.episode) { if (media?.media?.episodes || media?.media?.nextAiringEpisode?.episode) {
if (media.media.episodes || media.media.nextAiringEpisode?.episode > media.episode) { if (media.media.episodes || media.media.nextAiringEpisode?.episode > media.episode) {
completed = true completed = true
@ -942,7 +943,7 @@
<span class='material-icons ctrl' title='Mute [M]' data-name='toggleMute' on:click={toggleMute}> {muted ? 'volume_off' : 'volume_up'} </span> <span class='material-icons ctrl' title='Mute [M]' data-name='toggleMute' on:click={toggleMute}> {muted ? 'volume_off' : 'volume_up'} </span>
<input class='ctrl' type='range' min='0' max='1' step='any' data-name='setVolume' bind:value={volume} style='--value: {volume * 100}%' /> <input class='ctrl' type='range' min='0' max='1' step='any' data-name='setVolume' bind:value={volume} style='--value: {volume * 100}%' />
</div> </div>
<div class='ts mr-auto'>{toTS(targetTime, duration > 3600 ? 2 : 3)} / {toTS(duration - targetTime, duration > 3600 ? 2 : 3)}</div> <div class='ts mr-auto'>{toTS(targetTime, safeduration > 3600 ? 2 : 3)} / {toTS(safeduration - targetTime, safeduration > 3600 ? 2 : 3)}</div>
{#if 'audioTracks' in HTMLVideoElement.prototype && video?.audioTracks?.length > 1} {#if 'audioTracks' in HTMLVideoElement.prototype && video?.audioTracks?.length > 1}
<div class='dropdown dropup with-arrow' on:click={toggleDropdown}> <div class='dropdown dropup with-arrow' on:click={toggleDropdown}>
<span class='material-icons ctrl' title='Audio Tracks'> <span class='material-icons ctrl' title='Audio Tracks'>