diff options
Diffstat (limited to 'web')
-rw-r--r-- | web/script/player/mod.ts | 15 | ||||
-rw-r--r-- | web/script/player/player.ts | 17 | ||||
-rw-r--r-- | web/script/player/track.ts | 2 |
3 files changed, 25 insertions, 9 deletions
diff --git a/web/script/player/mod.ts b/web/script/player/mod.ts index 7a4b0ba..08193a7 100644 --- a/web/script/player/mod.ts +++ b/web/script/player/mod.ts @@ -56,11 +56,16 @@ function initialize_player(el: HTMLElement, node_id: string) { new Popup(button, popups, () => e("div", { class: "jsp-track-select-popup" }, ...(player.tracks ?? []) - .filter(t => get_track_kind(t.kind) == kind) - .map(t => e("div", - e("span", { class: "jsp-track-name" }, t.name), " ", - e("span", { class: "jsp-track-lang" }, t.language) - )) + .map((track, index) => ({ index, track })) + .filter(({ track }) => get_track_kind(track.kind) == kind) + .map(({ track, index }): HTMLElement => { + const active = player.active_tracks.value.find(ts => ts.track_index == index) !== undefined + return e("div", + e("span", { class: "jsp-track-stae" }, active ? "active" : ""), " ", + e("span", { class: "jsp-track-name" }, track.name), " ", + e("span", { class: "jsp-track-lang" }, track.language) + ) + }) ) ) return button 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() } diff --git a/web/script/player/track.ts b/web/script/player/track.ts index df7ab69..f40730f 100644 --- a/web/script/player/track.ts +++ b/web/script/player/track.ts @@ -45,7 +45,7 @@ export class PlayerTrack { constructor( private player: Player, private node_id: string, - private track_index: number, + public track_index: number, private metadata: SourceTrack, public index: JhlsTrackIndex, ) { |