init.mp4 appended to media source buffer

This commit is contained in:
Muaz Ahmad 2023-08-23 23:23:51 +05:00
parent e94d063422
commit 24b896824f

View file

@ -45,13 +45,19 @@ class VideoLoader {
this.playlist_loader = new PlaylistLoader(); this.playlist_loader = new PlaylistLoader();
this.player = document.getElementById(vid_tag_id); this.player = document.getElementById(vid_tag_id);
this.media_source = new MediaSource(); 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 init_frag = await this.fetch_video('/vid/' + this.stream_key + '/init.mp4');
let mime = (new MP4Tree(init_frag)).get_mime(); 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) { async fetch_video(uri) {