UNPKG

@aidenlx/player

Version:

Headless web components that make integrating media on the a web a breeze.

83 lines (82 loc) 2.15 kB
import "../../chunks/chunk.LNH2V2XS.js"; import { vdsEvent } from "@vidstack/foundation"; import { html } from "lit"; import { CanPlay } from "../CanPlay"; import { MediaProviderElement } from "../provider"; class FakeMediaProviderElement extends MediaProviderElement { constructor() { super(); Object.keys(this._store).forEach((key) => { Object.defineProperty(this, `emulate-${key.toLowerCase()}`, { set(value) { this._connectedQueue.queue(`emulate-${key}`, () => { this._store[key].set(value); if (key === "canPlay") { if (value) { this.mediaRequestQueue.start(); } else { this.mediaRequestQueue.stop(); } } }); } }); }); } connectedCallback() { super.connectedCallback(); if (this.canPlay) { this.forceMediaReady(); } } render() { return html`<slot></slot>`; } async forceMediaReady() { return this._handleMediaReady({ duration: 0 }); } _setCurrentTime(time) { this.dispatchEvent(vdsEvent("vds-seeking", { detail: time })); this.dispatchEvent(vdsEvent("vds-time-update", { detail: time })); this.dispatchEvent(vdsEvent("vds-seeked", { detail: time })); } _setMuted(muted) { this.dispatchEvent(vdsEvent("vds-volume-change", { detail: { volume: this.volume, muted } })); } _setVolume(volume) { this.dispatchEvent(vdsEvent("vds-volume-change", { detail: { volume, muted: this.muted } })); } get engine() { return void 0; } canPlayType() { return CanPlay.No; } async play() { this.dispatchEvent(vdsEvent("vds-play")); } async pause() { this.dispatchEvent(vdsEvent("vds-pause")); } async requestFullscreen() { await super.requestFullscreen(); this.dispatchEvent(vdsEvent("vds-fullscreen-change", { detail: true })); } async exitFullscreen() { await super.exitFullscreen(); this.dispatchEvent(vdsEvent("vds-fullscreen-change", { detail: false })); } } export { FakeMediaProviderElement };