diff options
Diffstat (limited to 'web/script/player/player.ts')
-rw-r--r-- | web/script/player/player.ts | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/web/script/player/player.ts b/web/script/player/player.ts index d988374..d76d8cb 100644 --- a/web/script/player/player.ts +++ b/web/script/player/player.ts @@ -93,9 +93,8 @@ export class Player { this.video.src = URL.createObjectURL(this.media_source) this.media_source.addEventListener("sourceopen", async () => { this.set_pers("Downloading track indecies...") - this.active_tracks.value.push((await PlayerTrack.new(this, this.node_id, 0, this.tracks![0]))!) // TODO unsafe and missing ui anyway - this.active_tracks.value.push((await PlayerTrack.new(this, this.node_id, 1, this.tracks![1]))!) - this.active_tracks.change() + await this.set_track_enabled(0, true) + await this.set_track_enabled(1, true) this.set_pers("Downloading initial segments...") this.update() await this.canplay.wait_for(true) @@ -106,6 +105,18 @@ export class Player { await Promise.all(this.active_tracks.value.map(t => t.update(newt ?? this.video.currentTime))) } + async set_track_enabled(index: number, state: boolean) { + console.log(`(${index}) set enabled ${state}`); + const active_index = this.active_tracks.value.findIndex(t => t.track_index == index) + if (!state && active_index !== undefined) { + const [track] = this.active_tracks.value.splice(active_index, 1) + track.destroy() + } else if (state && active_index === undefined) { + this.active_tracks.value.push((await PlayerTrack.new(this, this.node_id, index, this.tracks![index]))!) + } + this.active_tracks.change() + } + play() { this.video.play() } |