fix: filmstrip probe video — append to DOM, fix src/handler race, add timeout

This commit is contained in:
Zac Gaetano 2026-05-25 11:14:55 -04:00
parent 37c406bf4d
commit 0481fb3ecf

View file

@ -88,12 +88,19 @@ function AssetDetail({ asset, onClose }) {
let cancelled = false;
const build = async function() {
setFilmstripLoading(true);
try {
const probe = document.createElement('video');
probe.crossOrigin = 'anonymous';
probe.muted = true;
probe.playsInline = true;
probe.preload = 'auto';
probe.style.cssText = 'position:fixed;left:-9999px;top:-9999px;width:1px;height:1px;pointer-events:none';
document.body.appendChild(probe);
const timeout = setTimeout(function() {
probe.remove();
if (!cancelled) { setFilmFrames([]); setFilmstripLoading(false); }
cancelled = true;
}, 15000);
try {
if (streamType === 'hls') {
if (!window.Hls) throw new Error('hls.js not loaded');
await new Promise(function(resolve, reject) {
@ -107,10 +114,10 @@ function AssetDetail({ asset, onClose }) {
hls.attachMedia(probe);
});
} else {
probe.src = streamUrl;
await new Promise(function(resolve, reject) {
probe.onloadedmetadata = resolve;
probe.onerror = reject;
probe.src = streamUrl;
});
}
const frameCount = 28;
@ -146,6 +153,8 @@ function AssetDetail({ asset, onClose }) {
} catch (_) {
if (!cancelled) setFilmFrames([]);
} finally {
clearTimeout(timeout);
probe.remove();
if (!cancelled) setFilmstripLoading(false);
}
};