Mercurial > code > home > repos > video
changeset 8:f80f8c22752d
start PagePlayer, a singleton player that appears on top
author | drewp@bigasterisk.com |
---|---|
date | Sun, 09 Apr 2023 19:37:05 -0700 |
parents | de93b9133acb |
children | 9e94454560de |
files | src/PagePlayer.ts src/VideoPage.ts src/VideoSection.ts |
diffstat | 3 files changed, 97 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/PagePlayer.ts Sun Apr 09 19:37:05 2023 -0700 @@ -0,0 +1,53 @@ +import { LitElement, html, css, PropertyValues } from "lit"; +import { customElement, property } from "lit/decorators.js"; +import "shaka-video-element"; + +interface CustomVideoElement extends HTMLVideoElement {} + +export interface ShakaVideoElement extends CustomVideoElement {} + +@customElement("page-player") +export class PagePlayer extends LitElement { + @property({ type: String }) manifest: string | undefined; + @property({ type: String }) size: "hidden" | "big" | "full" = "hidden"; + player!: Element; + static styles = [ + css` + div { + z-index: 2; + position: fixed; + } + div.full { + inset: 0; + } + div.big { + inset: 5em; + } + div.hidden { + display: none; + } + shaka-video { + width: 100%; + height: 100%; + } + `, + ]; + + updated(oldVals: PropertyValues<this>) { + if (oldVals.get("size")) { + if (this.size == "hidden") { + const player = this.shadowRoot!.querySelector("shaka-video")! as ShakaVideoElement; + player.pause(); + } else if (this.size == "big") { + } else if (this.size == "full") { + } + } + } + render() { + return html` + <div class="${this.size}"> + <shaka-video src="${this.manifest}" controls></video> + </div> + `; + } +}
--- a/src/VideoPage.ts Sun Apr 09 19:36:07 2023 -0700 +++ b/src/VideoPage.ts Sun Apr 09 19:37:05 2023 -0700 @@ -1,7 +1,9 @@ import { LitElement, html, css } from "lit"; import { customElement, property } from "lit/decorators.js"; +import { PagePlayer } from "./PagePlayer"; export { VideoSection } from "./VideoSection"; - +export { PagePlayer } from "./PagePlayer"; +import { ShakaVideoElement } from "./PagePlayer"; interface VideoFile { webRelPath: string; label: string; @@ -81,15 +83,43 @@ margin: 5px; border-bottom-right-radius: 29px; } + #scrim { + position: absolute; + background: #000000b5; + inset: 0; + display: none; + } `, ]; - // allow only 1 to play. embiggen like pbskids does. render() { return html` <div id="path-segs">${this.pathSegs.map((seg) => html`<span><a href="./?${subdirQuery(seg.subdir)}">${seg.label}</a></span>`)}</div> ${this.subdirs.map((s) => html`<div class="subdir"><a href="${"./?" + subdirQuery(s.path)}">${s.label}</a></div>`)} - ${this.videos.map((v) => html`<video-section thumbRelPath="${v.thumbRelPath}" title="${v.label}" manifest=${v.webRelPath}></video-section>`)} + ${this.videos.map( + (v) => html`<video-section @playVideo=${this.playVideo} thumbRelPath="${v.thumbRelPath}" title="${v.label}" manifest=${v.webRelPath}></video-section>` + )} + <div id="scrim" @click=${this.closePlayer}></div> + <page-player manifest=""></page-player> `; } + playVideo(ev: CustomEvent) { + const player = this.shadowRoot!.querySelector("page-player")! as PagePlayer; + + player.manifest = ev.detail.manifest; + const sv = player.shadowRoot!.querySelector("shaka-video")! as ShakaVideoElement; + + sv.src = ev.detail.manifest; + sv.load().then(() => { + sv.play(); + }); + player.size = "big"; + this.shadowRoot!.querySelector("#scrim")!.style.display = "block"; + } + closePlayer() { + const player = this.shadowRoot!.querySelector("page-player")! as PagePlayer; + player.size = "hidden"; + + this.shadowRoot!.querySelector("#scrim")!.style.display = "none"; + } }
--- a/src/VideoSection.ts Sun Apr 09 19:36:07 2023 -0700 +++ b/src/VideoSection.ts Sun Apr 09 19:37:05 2023 -0700 @@ -18,34 +18,26 @@ color: white; width: 300px; } - #video.big { - z-index: 2; - position: fixed; - left: 0px; - top: 0px; - } `, ]; render() { - const vidCls = this.big ? "big" : ""; - const inx = 20, - iny = 50; - const inw = 300, - inh = 150; - const outw = 720, - outh = 480; - const scl = outh / inh; - const tx = (document.body.clientWidth - inw * scl) / 2, - ty = (document.body.clientHeight - inh * scl) / 2; - const style = this.big ? `transform: translate(${-inx - inw / 2}px,${-iny - inh / 2}px) scale(${outh / inh}) translate(${tx}px,${ty}px);` : ""; return html` - <section> + <section @click=${this.click}> <h1>${this.title}</h1> - <!-- <shaka-video class="${vidCls}" style="${style}" id="video" width="720" height="480" src="${this.manifest}" controls></video>--> <img src="${this.thumbRelPath}" /> </section> `; } + click() { + this.dispatchEvent( + new CustomEvent("playVideo", { + detail: { + manifest: this.manifest, + zoomFrom: "my location", + }, + }) + ); + } updated() { // const el=this.querySelector("#video") // console.log(el.clientWidth);