mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-24 14:41:20 -08:00
fix(auto-thumbnail): [PKG-AUTO-THUMB-12] release stalled metadata loads
This commit is contained in:
1 parent
d3aa4bbfe4
commit
42ddead0cd
20 files changed
+6048
-20
No files matched your search
@@ -8,10 +8,19 @@ export default function extract(job: ExtractionJob, config: ExtractionConfig) {
|
||||
const video = createVideo(job)
|
||||
if (!job.active())
|
||||
return
|
||||
let metadataTimer: ReturnType<typeof setTimeout> | null = null
|
||||
const clearMetadataTimer = () => {
|
||||
const previous = metadataTimer
|
||||
metadataTimer = null
|
||||
if (previous !== null)
|
||||
clearTimeout(previous)
|
||||
}
|
||||
job.own(clearMetadataTimer)
|
||||
video.onerror = job.guard(() => {
|
||||
throw video.error || new Error('Auto-thumbnail media failed to load')
|
||||
})
|
||||
video.onloadedmetadata = job.guard(() => {
|
||||
clearMetadataTimer()
|
||||
video.onloadedmetadata = null
|
||||
const duration = video.duration
|
||||
const videoHeight = video.videoHeight
|
||||
@@ -70,6 +79,15 @@ export default function extract(job: ExtractionJob, config: ExtractionConfig) {
|
||||
})
|
||||
seek()
|
||||
})
|
||||
if (job.active())
|
||||
video.src = config.url
|
||||
if (!job.active())
|
||||
return
|
||||
metadataTimer = setTimeout(job.guard(() => {
|
||||
if (metadataTimer !== null)
|
||||
throw new Error('Auto-thumbnail metadata timed out')
|
||||
}), 30000)
|
||||
if (!job.active()) {
|
||||
clearMetadataTimer()
|
||||
return
|
||||
}
|
||||
video.src = config.url
|
||||
}
|
||||
Reference in new issue
Block a user