diff src/VideoPage.ts @ 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 ccfea3625cf6
children e60be5d74c07
line wrap: on
line diff
--- 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";
+  }
 }