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