diff options
author | metamuffin <metamuffin@disroot.org> | 2023-12-11 00:21:13 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-12-11 00:21:13 +0100 |
commit | b42ded3fcaf2088e464c5d4861449879a90c6ba0 (patch) | |
tree | eff66c1c39a8e2ec61f121d446964d61c24ac7e7 /web/script/player/player.ts | |
parent | b050eb5c37e68a6fdd57068d4e73748bea3b0a11 (diff) | |
download | jellything-b42ded3fcaf2088e464c5d4861449879a90c6ba0.tar jellything-b42ded3fcaf2088e464c5d4861449879a90c6ba0.tar.bz2 jellything-b42ded3fcaf2088e464c5d4861449879a90c6ba0.tar.zst |
horrible midnight fixes and some fancy popups in the player
Diffstat (limited to 'web/script/player/player.ts')
-rw-r--r-- | web/script/player/player.ts | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/web/script/player/player.ts b/web/script/player/player.ts index 81a315e..9151a2a 100644 --- a/web/script/player/player.ts +++ b/web/script/player/player.ts @@ -1,5 +1,5 @@ import { OVar, e } from "../jshelper/mod.ts"; -import { JhlsMetadata, TimeRange } from "./jhls.d.ts"; +import { JhlsMetadata, JhlsTrack, TimeRange } from "./jhls.d.ts"; import { SegmentDownloader } from "./download.ts"; import { PlayerTrack } from "./track.ts"; import { ProfileSelector } from "./profiles.ts"; @@ -9,7 +9,8 @@ export interface BufferRange extends TimeRange { status: "buffered" | "loading" export class Player { public video = e("video") public media_source = new MediaSource(); - public tracks = new OVar<PlayerTrack[]>([]); + public tracks?: JhlsTrack[]; + public active_tracks = new OVar<PlayerTrack[]>([]); public downloader: SegmentDownloader = new SegmentDownloader(); public profile_selector!: ProfileSelector @@ -79,6 +80,7 @@ export class Player { if (!res.ok) return this.error.value = "Cannot download JHLS metadata" const metadata = await res.json() as JhlsMetadata this.set_pers() + this.tracks = metadata.tracks this.profile_selector = new ProfileSelector(this, this.downloader.bandwidth, metadata) this.set_pers("Checking codec support...") @@ -88,17 +90,17 @@ export class Player { this.video.src = URL.createObjectURL(this.media_source) this.media_source.addEventListener("sourceopen", async () => { this.set_pers("Initializing Media Extensions...") - this.tracks.value.push(await PlayerTrack.new(this, this.node_id, 0, metadata.tracks[0])) - this.tracks.value.push(await PlayerTrack.new(this, this.node_id, 1, metadata.tracks[1])) - this.tracks.change() - this.set_pers("Fetching initial segments...") + this.active_tracks.value.push(await PlayerTrack.new(this, this.node_id, 0, metadata.tracks[0])) + this.active_tracks.value.push(await PlayerTrack.new(this, this.node_id, 1, metadata.tracks[1])) + this.active_tracks.change() + this.set_pers("Downloading initial segments...") this.update() await this.canplay.wait_for(true) this.set_pers() }) } async update(newt?: number) { - await Promise.all(this.tracks.value.map(t => t.update(newt ?? this.video.currentTime))) + await Promise.all(this.active_tracks.value.map(t => t.update(newt ?? this.video.currentTime))) } play() { |