From d99ddd65e23f56410d47d95992a998dc6de0a586 Mon Sep 17 00:00:00 2001 From: mrjvs Date: Fri, 1 Sep 2023 15:52:39 +0200 Subject: [PATCH] Add basic controller --- src/stores/player/controllers/base.ts | 20 ++++++++++++++++++-- src/stores/player/controllers/types.ts | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/stores/player/controllers/base.ts b/src/stores/player/controllers/base.ts index 27021595..397bedc7 100644 --- a/src/stores/player/controllers/base.ts +++ b/src/stores/player/controllers/base.ts @@ -1,5 +1,21 @@ import { Controller } from "@/stores/player/controllers/types"; -function useBaseController(el: HTMLVideoElement): Controller { - return {}; +export function useBaseController(): Controller { + let el: HTMLVideoElement | undefined; + + return { + registerVideoElement(video) { + el = video; + }, + pause() { + el?.pause(); + }, + play() { + el?.play(); + }, + setVolume(target) { + if (!el) return; + el.volume = target; + }, + }; } diff --git a/src/stores/player/controllers/types.ts b/src/stores/player/controllers/types.ts index 32a30c81..46904497 100644 --- a/src/stores/player/controllers/types.ts +++ b/src/stores/player/controllers/types.ts @@ -2,5 +2,5 @@ export interface Controller { pause(): void; play(): void; setVolume(target: number): void; - registerVideoElement(): void; + registerVideoElement(videoElement: HTMLVideoElement): void; }