movie-web/src/components/video/hooks/controlVideo.ts

36 lines
741 B
TypeScript
Raw Normal View History

2023-01-08 15:37:16 +01:00
export interface PlayerControls {
play(): void;
pause(): void;
2023-01-08 16:23:42 +01:00
exitFullscreen(): void;
enterFullscreen(): void;
2023-01-08 15:37:16 +01:00
}
export const initialControls: PlayerControls = {
play: () => null,
pause: () => null,
2023-01-08 16:23:42 +01:00
enterFullscreen: () => null,
exitFullscreen: () => null,
2023-01-08 15:37:16 +01:00
};
2023-01-08 16:23:42 +01:00
export function populateControls(
player: HTMLVideoElement,
wrapper: HTMLDivElement
): PlayerControls {
2023-01-08 15:37:16 +01:00
return {
play() {
player.play();
},
pause() {
player.pause();
},
2023-01-08 16:23:42 +01:00
enterFullscreen() {
if (!document.fullscreenEnabled || document.fullscreenElement) return;
wrapper.requestFullscreen();
},
exitFullscreen() {
if (!document.fullscreenElement) return;
document.exitFullscreen();
},
2023-01-08 15:37:16 +01:00
};
}