From 39a239caba79f2ba902083211a723626a002ec87 Mon Sep 17 00:00:00 2001 From: "Dr. Ralf S. Engelschall" Date: Fri, 3 Nov 2023 09:14:01 +0100 Subject: [PATCH] hls: bugfix, stability and resilience improvements in the webpage - STABILITY: await MEDIA_ATTACHED event before performing "loadSource" on HLS - STABILITY: await MANIFEST_PARSED event before performing "play" on video element - RESILIENCE: on "MEDIA_ERROR" event perform "recoverMediaError" on HLS --- internal/core/hls_index.html | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/internal/core/hls_index.html b/internal/core/hls_index.html index 3c75b92f..d33db6c8 100644 --- a/internal/core/hls_index.html +++ b/internal/core/hls_index.html @@ -33,18 +33,22 @@ const create = (video) => { }); hls.on(Hls.Events.ERROR, (evt, data) => { - if (data.fatal) { + if (data.type === Hls.ErrorTypes.MEDIA_ERROR) + hls.recoverMediaError(); + else if (data.fatal) { hls.destroy(); - - setTimeout(create, 2000); + setTimeout(() => create(video), 2000); } }); - hls.loadSource('index.m3u8' + window.location.search); + hls.on(Hls.Events.MEDIA_ATTACHED, () => { + hls.loadSource('index.m3u8' + window.location.search); + }); + hls.on(Hls.Events.MANIFEST_PARSED, () => { + video.play(); + }); hls.attachMedia(video); - video.play(); - } else if (video.canPlayType('application/vnd.apple.mpegurl')) { // since it's not possible to detect timeout errors in iOS, // wait for the playlist to be available before starting the stream