diff --git a/front/packages/ui/src/player/video.tsx b/front/packages/ui/src/player/video.tsx index 8094c4bb..0d886693 100644 --- a/front/packages/ui/src/player/video.tsx +++ b/front/packages/ui/src/player/video.tsx @@ -33,17 +33,98 @@ export * from "react-native-video"; import { Font } from "@kyoo/models"; import { IconButton, Menu } from "@kyoo/primitives"; -import { ComponentProps } from "react"; -import Video from "react-native-video"; -export default Video; +import { ComponentProps, useRef } from "react"; +import { atom, useAtom, useAtomValue, useSetAtom } from "jotai"; +import NativeVideo, { OnLoadData } from "react-native-video"; +import { useTranslation } from "react-i18next"; +import { PlayMode, playModeAtom } from "./state"; -// TODO: Implement those for mobile. +const infoAtom = atom(null); +const videoAtom = atom(0); +const audioAtom = atom(0); + +const Video = ({ onLoad, ...props }: ComponentProps) => { + const player = useRef(null); + const setInfo = useSetAtom(infoAtom); + const video = useAtomValue(videoAtom); + const audio = useAtomValue(audioAtom); + + return ( + { + player.current = ref; + }} + onLoad={(info) => { + setInfo(info); + onLoad?.(info); + }} + selectedVideoTrack={video === -1 ? { type: "auto" } : { type: "resolution", value: video }} + selectedAudioTrack={{ type: "index", value: audio }} + {...props} + /> + ); +}; + +export default Video; type CustomMenu = ComponentProps>>; export const AudiosMenu = (props: CustomMenu) => { - return ; + const info = useAtomValue(infoAtom); + const [audio, setAudio] = useAtom(audioAtom); + + if (!info || info.audioTracks.length < 2) return null; + + return ( + + {info.audioTracks.map((x) => ( + setAudio(x.index)} + /> + ))} + + ); }; export const QualitiesMenu = (props: CustomMenu) => { - return ; + const { t } = useTranslation(); + const info = useAtomValue(infoAtom); + const [mode, setPlayMode] = useAtom(playModeAtom); + const [video, setVideo] = useAtom(videoAtom); + + return ( + + setPlayMode(PlayMode.Direct)} + /> + { + setPlayMode(PlayMode.Hls); + setVideo(-1); + }} + /> + {/* TODO: Support video tracks when the play mode is not hls. */} + {info?.videoTracks.map((x) => ( + { + setPlayMode(PlayMode.Hls); + setVideo(x.height); + }} + /> + ))} + + ); };