1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2024-12-26 15:37:41 +01:00
smov/src/components/player/hooks/usePlayer.ts

35 lines
964 B
TypeScript
Raw Normal View History

2023-07-23 16:30:22 +02:00
import { MWStreamType } from "@/backend/helpers/streams";
import { useInitializePlayer } from "@/components/player/hooks/useInitializePlayer";
import { PlayerMeta, playerStatus } from "@/stores/player/slices/source";
2023-07-23 16:30:22 +02:00
import { usePlayerStore } from "@/stores/player/store";
export interface Source {
url: string;
type: MWStreamType;
}
export function usePlayer() {
const setStatus = usePlayerStore((s) => s.setStatus);
const setMeta = usePlayerStore((s) => s.setMeta);
2023-09-30 20:57:00 +02:00
const status = usePlayerStore((s) => s.status);
const display = usePlayerStore((s) => s.display);
const reset = usePlayerStore((s) => s.reset);
const { init } = useInitializePlayer();
2023-07-23 16:30:22 +02:00
return {
reset,
2023-09-30 20:57:00 +02:00
status,
setMeta(meta: PlayerMeta) {
setMeta(meta);
},
2023-07-23 16:30:22 +02:00
playMedia(source: Source) {
2023-09-30 20:57:00 +02:00
display?.load(source);
2023-07-23 16:30:22 +02:00
setStatus(playerStatus.PLAYING);
init();
2023-07-23 16:30:22 +02:00
},
setScrapeStatus() {
setStatus(playerStatus.SCRAPING);
},
2023-07-23 16:30:22 +02:00
};
}