From ffe4a2d1e76ed804f878a016fc8fe487411cfa7b Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Sat, 14 Aug 2021 16:30:41 +0200 Subject: [PATCH] hls: support reading on iOS Safari --- internal/core/hls_remuxer.go | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/internal/core/hls_remuxer.go b/internal/core/hls_remuxer.go index 0d655fb2..ecd5620e 100644 --- a/internal/core/hls_remuxer.go +++ b/internal/core/hls_remuxer.go @@ -48,24 +48,29 @@ const index = ` const create = () => { const video = document.getElementById('video'); - const hls = new Hls({ - progressive: false, - }); + if (video.canPlayType('application/vnd.apple.mpegurl')) { + video.src = 'stream.m3u8'; + video.play(); + } else { + const hls = new Hls({ + progressive: false, + }); - hls.on(Hls.Events.ERROR, (evt, data) => { - if (data.fatal) { - hls.destroy(); + hls.on(Hls.Events.ERROR, (evt, data) => { + if (data.fatal) { + hls.destroy(); - setTimeout(() => { - create(); - }, 2000); - } - }); + setTimeout(() => { + create(); + }, 2000); + } + }); - hls.loadSource('stream.m3u8'); - hls.attachMedia(video); + hls.loadSource('stream.m3u8'); + hls.attachMedia(video); - video.play(); + video.play(); + } } create();