From 85cbf0e3351afb789471b4b7b7abbecc69fe171d Mon Sep 17 00:00:00 2001 From: Muaz Ahmad Date: Thu, 24 Aug 2023 00:11:09 +0500 Subject: [PATCH] video segment fetch loop, it just works --- hls-player.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hls-player.js b/hls-player.js index db0198e..5d5faab 100644 --- a/hls-player.js +++ b/hls-player.js @@ -58,6 +58,16 @@ class VideoLoader { this.media_buffer = this.media_source.addSourceBuffer(mime); this.media_buffer.mode = 'segments'; this.media_buffer.appendBuffer(init_frag); + this.fetch_new_segments(); + } + + async fetch_new_segments() { + while (this.playlist_loader.new_segments.length > 0) { + let segment_uri = this.playlist_loader.new_segments.shift(); + let segment_stream = await this.fetch_video(segment_uri); + this.media_buffer.appendBuffer(segment_stream); + } + setTimeout(this.fetch_new_segments.bind(this), this.playlist_loader.refresh_interval * 1000); } async fetch_video(uri) {