aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--web/script/player/mod.ts31
-rw-r--r--web/script/player/player.ts2
2 files changed, 24 insertions, 9 deletions
diff --git a/web/script/player/mod.ts b/web/script/player/mod.ts
index 1d4267f..2dad414 100644
--- a/web/script/player/mod.ts
+++ b/web/script/player/mod.ts
@@ -49,15 +49,28 @@ function initialize_player(el: HTMLElement, node_id: string) {
const popups = e("div")
const track_select = (kind: TrackKind) => {
- let enabled = true
- const button = e("button", MEDIA_KIND_ICONS[kind][+enabled], {
- class: "icon",
- onclick: () => {
- // sync_state.value = new Playersync(player, logger, "test")
- enabled = !enabled
- button.textContent = MEDIA_KIND_ICONS[kind][+enabled]
- }
- })
+ const button = e("div", player.active_tracks.map(_ => {
+ const active = player.active_tracks.value.filter(
+ ts => get_track_kind(player.tracks![ts.track_index].kind) == kind)
+ const enabled = active.length > 0
+ return e("button", MEDIA_KIND_ICONS[kind][+enabled], {
+ class: "icon",
+ onclick: () => {
+ if (enabled) {
+ for (const t of active) {
+ player.set_track_enabled(t.track_index, false)
+ }
+ } else {
+ const all_kind = (player.tracks ?? [])
+ .map((track, index) => ({ index, track }))
+ .filter(({ track }) => get_track_kind(track.kind) == kind)
+ if (all_kind.length < 1) return
+ player.set_track_enabled(all_kind[0].index, true)
+ }
+
+ }
+ })
+ }))
const volume = () => {
const slider = e("input")
slider.type = "range"
diff --git a/web/script/player/player.ts b/web/script/player/player.ts
index 6589772..4f322a9 100644
--- a/web/script/player/player.ts
+++ b/web/script/player/player.ts
@@ -137,9 +137,11 @@ export class Player {
console.log(`(${index}) set enabled ${state}`);
const active_index = this.active_tracks.value.findIndex(t => t.track_index == index)
if (!state && active_index != -1) {
+ this.logger?.log(`Disabled track ${index}.`)
const [track] = this.active_tracks.value.splice(active_index, 1)
track.abort.abort()
} else if (state && active_index == -1) {
+ this.logger?.log(`Enabled track ${index}.`)
this.active_tracks.value.push((await create_track(this, this.node_id, index, this.tracks![index]))!)
if (update) await this.update()
}