fix: filmstrip probe video — append to DOM, fix src/handler race, add timeout
This commit is contained in:
parent
37c406bf4d
commit
0481fb3ecf
1 changed files with 15 additions and 6 deletions
|
|
@ -88,12 +88,19 @@ function AssetDetail({ asset, onClose }) {
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
const build = async function() {
|
const build = async function() {
|
||||||
setFilmstripLoading(true);
|
setFilmstripLoading(true);
|
||||||
try {
|
|
||||||
const probe = document.createElement('video');
|
const probe = document.createElement('video');
|
||||||
probe.crossOrigin = 'anonymous';
|
probe.crossOrigin = 'anonymous';
|
||||||
probe.muted = true;
|
probe.muted = true;
|
||||||
probe.playsInline = true;
|
probe.playsInline = true;
|
||||||
probe.preload = 'auto';
|
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 (streamType === 'hls') {
|
||||||
if (!window.Hls) throw new Error('hls.js not loaded');
|
if (!window.Hls) throw new Error('hls.js not loaded');
|
||||||
await new Promise(function(resolve, reject) {
|
await new Promise(function(resolve, reject) {
|
||||||
|
|
@ -107,10 +114,10 @@ function AssetDetail({ asset, onClose }) {
|
||||||
hls.attachMedia(probe);
|
hls.attachMedia(probe);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
probe.src = streamUrl;
|
|
||||||
await new Promise(function(resolve, reject) {
|
await new Promise(function(resolve, reject) {
|
||||||
probe.onloadedmetadata = resolve;
|
probe.onloadedmetadata = resolve;
|
||||||
probe.onerror = reject;
|
probe.onerror = reject;
|
||||||
|
probe.src = streamUrl;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const frameCount = 28;
|
const frameCount = 28;
|
||||||
|
|
@ -146,6 +153,8 @@ function AssetDetail({ asset, onClose }) {
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
if (!cancelled) setFilmFrames([]);
|
if (!cancelled) setFilmFrames([]);
|
||||||
} finally {
|
} finally {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
probe.remove();
|
||||||
if (!cancelled) setFilmstripLoading(false);
|
if (!cancelled) setFilmstripLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue