feat: added a basic native adapter

it uses basic html api to play the video and do normal things on video like pause and seek
This commit is contained in:
2026-04-23 01:25:03 +03:30
parent ba991b8156
commit 72af0641dd
2 changed files with 73 additions and 0 deletions

72
src/adapters/Native.ts Normal file
View File

@@ -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;
}
}

1
src/adapters/index.ts Normal file
View File

@@ -0,0 +1 @@
export { NativeAdapter } from "./Native";