diff --git a/src/adapters/Native.ts b/src/adapters/Native.ts new file mode 100644 index 0000000..bac7f27 --- /dev/null +++ b/src/adapters/Native.ts @@ -0,0 +1,72 @@ +/** + * native video + * + * author: db123 at db + * creation: 23/4/2026 + */ + +import { AdapterAPI } from "../types"; + +export class NativeAdapter implements AdapterAPI { + private video: HTMLVideoElement; + + /** + * @param video The targeted video element + */ + constructor(video: HTMLVideoElement) { + this.video = video; + } + + load(): void { + this.video.load(); + } + + play(): void { + this.video.play().catch((e) => console.warn("Play failed:", e)); + } + + pause(): void { + this.video.pause(); + } + + destroy(): void { + this.pause(); + this.video.load(); + } + + seek(time: number): void { + if (this.video.fastSeek) { + this.video.fastSeek(time); + } else { + this.video.currentTime = time; + } + } + + currentTime(): number { + return this.video.currentTime; + } + + duration(): number { + return this.video.duration; + } + + volume(volume: number): void { + this.video.volume = volume; + } + + currentVolume(): number { + return this.video.volume; + } + + mute(muted?: boolean): void { + if (muted !== undefined) { + this.video.muted = muted; + } else { + this.video.muted = !this.video.muted; + } + } + + muted(): boolean { + return this.video.muted; + } +} diff --git a/src/adapters/index.ts b/src/adapters/index.ts new file mode 100644 index 0000000..56f7949 --- /dev/null +++ b/src/adapters/index.ts @@ -0,0 +1 @@ +export { NativeAdapter } from "./Native";