fix probing on wav

This commit is contained in:
RandyJC
2025-12-08 21:51:49 +01:00
parent 6420544f35
commit 03fdeb643a

View File

@@ -274,20 +274,31 @@ const QuizEditor = ({ quizzList, onBack, onListUpdate }: Props) => {
el.crossOrigin = "anonymous" el.crossOrigin = "anonymous"
el.preload = "metadata" el.preload = "metadata"
el.src = url el.src = url
el.load()
await new Promise<void>((resolve, reject) => { await new Promise<void>((resolve, reject) => {
const cleanup = () => { const cleanup = () => {
el.onloadedmetadata = null el.onloadedmetadata = null
el.onloadeddata = null
el.oncanplaythrough = null
el.onerror = null el.onerror = null
} }
el.onloadedmetadata = () => { const done = () => {
cleanup() cleanup()
resolve() resolve()
} }
el.onloadedmetadata = done
el.onloadeddata = done
el.oncanplaythrough = done
el.onerror = () => { el.onerror = () => {
cleanup() cleanup()
reject(new Error("Failed to load media metadata")) reject(new Error("Failed to load media metadata"))
} }
// safety timeout
setTimeout(() => {
cleanup()
reject(new Error("Timed out loading media metadata"))
}, 5000)
}) })
const duration = el.duration const duration = el.duration
@@ -657,18 +668,20 @@ const QuizEditor = ({ quizzList, onBack, onListUpdate }: Props) => {
</span> </span>
</label> </label>
<div className="flex flex-wrap items-center gap-2"> {question.media?.type !== "image" && question.media?.url && (
<Button <div className="flex flex-wrap items-center gap-2">
className="bg-gray-800" <Button
onClick={() => adjustTimingWithMedia(qIndex, question.media)} className="bg-gray-800"
disabled={!question.media?.url || probing[qIndex]} onClick={() => adjustTimingWithMedia(qIndex, question.media)}
> disabled={probing[qIndex]}
{probing[qIndex] ? "Probing..." : "Set timing from media"} >
</Button> {probing[qIndex] ? "Probing..." : "Set timing from media"}
<span className="text-xs text-gray-500"> </Button>
Probes audio/video duration and bumps cooldown/answer time if needed. <span className="text-xs text-gray-500">
</span> Probes audio/video duration and bumps cooldown/answer time if needed.
</div> </span>
</div>
)}
<div className="flex flex-wrap gap-2"> <div className="flex flex-wrap gap-2">
<Button <Button