diff --git a/src/core/VideoPlayer.ts b/src/core/VideoPlayer.ts index 0211123..c25e3b1 100644 --- a/src/core/VideoPlayer.ts +++ b/src/core/VideoPlayer.ts @@ -5,26 +5,32 @@ * creation: 21/4/2026 */ +import { NativeAdapter } from "../adapters"; import { AdapterAPI, PlayerConfig } from "../types/index"; export class VP { - private videoElement: HTMLElement | null; - private videoSources?: NodeListOf; + private video: HTMLVideoElement | null; + private videoSrc?: NodeListOf; private config?: PlayerConfig; private adapter?: AdapterAPI; /** - * @param {string} video The targeted video element - * @param {PlayerConfig} config The config array + * @param video The targeted video element or id + * @param config The config array */ constructor(video: string | HTMLVideoElement, config: PlayerConfig) { this.config = config; + if (video instanceof HTMLVideoElement) { - this.videoElement = video; + this.video = video; } else { - this.videoElement = document.querySelector(video); + this.video = document.querySelector(video); } - this.videoSources = this.videoElement?.querySelectorAll("source"); - let adapter = this.config["type"]; + if (!this.video) { + throw new Error(`Video element not found: ${video}`); + } + + this.videoSrc = this.video?.querySelectorAll("source"); + this.adapter = new NativeAdapter(this.video); } }