From 24b896824fa9e90ae66ddabf90df96a60b109e74 Mon Sep 17 00:00:00 2001 From: Muaz Ahmad Date: Wed, 23 Aug 2023 23:23:51 +0500 Subject: [PATCH] init.mp4 appended to media source buffer --- hls-player.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/hls-player.js b/hls-player.js index f84b2b3..db0198e 100644 --- a/hls-player.js +++ b/hls-player.js @@ -45,13 +45,19 @@ class VideoLoader { this.playlist_loader = new PlaylistLoader(); this.player = document.getElementById(vid_tag_id); this.media_source = new MediaSource(); - this.prepare_buffer(); + this.media_source.addEventListener('sourceopen', this.prepare_buffer.bind(this)); + this.player.src = window.URL.createObjectURL(this.media_source); } - async prepare_buffer() { + async prepare_buffer(_) { let init_frag = await this.fetch_video('/vid/' + this.stream_key + '/init.mp4'); let mime = (new MP4Tree(init_frag)).get_mime(); - console.log(mime); + if (!MediaSource.isTypeSupported(mime)) { + return; + } + this.media_buffer = this.media_source.addSourceBuffer(mime); + this.media_buffer.mode = 'segments'; + this.media_buffer.appendBuffer(init_frag); } async fetch_video(uri) {