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:
72
src/adapters/Native.ts
Normal file
72
src/adapters/Native.ts
Normal 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
1
src/adapters/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export { NativeAdapter } from "./Native";
|
||||||
Reference in New Issue
Block a user