2023-07-23 16:30:22 +02:00
|
|
|
import { MWStreamType } from "@/backend/helpers/streams";
|
2023-10-08 17:48:48 +02:00
|
|
|
import { useInitializePlayer } from "@/components/player/hooks/useInitializePlayer";
|
2023-10-08 18:16:30 +02:00
|
|
|
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);
|
2023-10-08 18:16:30 +02:00
|
|
|
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);
|
2023-10-08 17:48:48 +02:00
|
|
|
const { init } = useInitializePlayer();
|
2023-07-23 16:30:22 +02:00
|
|
|
|
|
|
|
return {
|
2023-09-30 20:57:00 +02:00
|
|
|
status,
|
2023-10-08 18:16:30 +02:00
|
|
|
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);
|
2023-10-08 17:48:48 +02:00
|
|
|
init();
|
2023-07-23 16:30:22 +02:00
|
|
|
},
|
2023-10-01 17:34:37 +02:00
|
|
|
setScrapeStatus() {
|
|
|
|
setStatus(playerStatus.SCRAPING);
|
|
|
|
},
|
2023-07-23 16:30:22 +02:00
|
|
|
};
|
|
|
|
}
|