|
|
|
@ -103,31 +103,39 @@ async function attachPlayer(url) { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
const { default: Hls } = await import('hls.js') |
|
|
|
if (seq !== attachSeq) return |
|
|
|
if (!Hls.isSupported()) { |
|
|
|
emit('error') |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
hls = new Hls({ enableWorker: true, lowLatencyMode: true }) |
|
|
|
hls.on(Hls.Events.ERROR, (_event, data) => { |
|
|
|
if (seq !== attachSeq) return |
|
|
|
if (data?.fatal) emit('error') |
|
|
|
}) |
|
|
|
hls.loadSource(url) |
|
|
|
hls.attachMedia(video) |
|
|
|
hls.on(Hls.Events.MANIFEST_PARSED, () => { |
|
|
|
try { |
|
|
|
const { default: Hls } = await import('hls.js') |
|
|
|
if (seq !== attachSeq) return |
|
|
|
video.play().catch(() => {}) |
|
|
|
}) |
|
|
|
if (!Hls.isSupported()) { |
|
|
|
emit('error') |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
hls = new Hls({ enableWorker: true, lowLatencyMode: true }) |
|
|
|
hls.on(Hls.Events.ERROR, (_event, data) => { |
|
|
|
if (seq !== attachSeq) return |
|
|
|
if (data?.fatal) emit('error') |
|
|
|
}) |
|
|
|
hls.loadSource(url) |
|
|
|
hls.attachMedia(video) |
|
|
|
hls.on(Hls.Events.MANIFEST_PARSED, () => { |
|
|
|
if (seq !== attachSeq) return |
|
|
|
video.play().catch(() => {}) |
|
|
|
}) |
|
|
|
} catch (_) { |
|
|
|
if (seq === attachSeq) emit('error') |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
watch( |
|
|
|
() => props.playUrl, |
|
|
|
(url) => { |
|
|
|
if (playable.value) attachPlayer(url) |
|
|
|
else destroyPlayer() |
|
|
|
if (playable.value) { |
|
|
|
attachPlayer(url).catch(() => {}) |
|
|
|
} else { |
|
|
|
attachSeq += 1 |
|
|
|
destroyPlayer() |
|
|
|
} |
|
|
|
}, |
|
|
|
{ immediate: true } |
|
|
|
) |
|
|
|
|