diff --git a/src/core/VideoPlayer.ts b/src/core/VideoPlayer.ts index e4575fb..dfa387d 100644 --- a/src/core/VideoPlayer.ts +++ b/src/core/VideoPlayer.ts @@ -1,5 +1,5 @@ /** - * main player + * main player and orchest * * author: db123 at db * creation: 21/4/2026 @@ -9,7 +9,7 @@ import { NativeAdapter } from "../adapters"; import { AdapterAPI, PlayerConfig } from "../types/index"; export class VP { - private video: HTMLVideoElement | null; + private video: HTMLVideoElement; private videoSrc?: NodeListOf; private config?: PlayerConfig; private adapter: AdapterAPI; @@ -21,17 +21,55 @@ export class VP { constructor(video: string | HTMLVideoElement, config: PlayerConfig) { this.config = config; + this.video = this.videoElement(video); + + this.videoSrc = this.video?.querySelectorAll("source"); + + this.adapter = this.adapterInit(config.type); + + this.info(); + } + + private info(): void { + console.info(` +==================================== + VP = VideoPlayer by db +https://git.db123.ir/db/VideoPlayer +==================================== +`); + } + + private videoElement(video: string | HTMLVideoElement): HTMLVideoElement { + let videoEl; if (video instanceof HTMLVideoElement) { - this.video = video; + videoEl = video; } else { - this.video = document.querySelector(video); + videoEl = document.querySelector(video); } - if (!this.video) { + if (!videoEl) { throw new Error(`Video element not found: ${video}`); } + return videoEl; + } - this.videoSrc = this.video?.querySelectorAll("source"); - this.adapter = new NativeAdapter(this.video); + private adapterInit(type: string = "native"): AdapterAPI { + switch (type) { + case "native": { + return new NativeAdapter(this.video); + } + + case "hls": { + throw new Error(`Adapter not implemented: ${type}`); + } + + case "dash": { + throw new Error(`Adapter not implemented: ${type}`); + } + + default: { + throw new Error(`Adapter not found: ${type}`); + } + } } load(): void {