aboutsummaryrefslogtreecommitdiff
path: root/web/script/player/player.ts
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-01-15 13:42:25 +0100
committermetamuffin <metamuffin@disroot.org>2024-01-15 13:42:25 +0100
commit31c3529ec2f8d934711d1ad2547e73c84a59878f (patch)
tree6b41841db9dafcbf9c6ed168eb0a54d8837fd63b /web/script/player/player.ts
parenta0fd6f2943d69d2f3e13fcf80fb567bb821eef9f (diff)
downloadjellything-31c3529ec2f8d934711d1ad2547e73c84a59878f.tar
jellything-31c3529ec2f8d934711d1ad2547e73c84a59878f.tar.bz2
jellything-31c3529ec2f8d934711d1ad2547e73c84a59878f.tar.zst
break player
Diffstat (limited to 'web/script/player/player.ts')
-rw-r--r--web/script/player/player.ts17
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()
}