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) {