diff --git a/front/packages/ui/src/player/state.tsx b/front/packages/ui/src/player/state.tsx index 094443b8..3f1d2422 100644 --- a/front/packages/ui/src/player/state.tsx +++ b/front/packages/ui/src/player/state.tsx @@ -18,13 +18,10 @@ * along with Kyoo. If not, see . */ -import { Font, Track, WatchItem } from "@kyoo/models"; -import { atom, useAtom, useAtomValue, useSetAtom } from "jotai"; -import { RefObject, useEffect, useLayoutEffect, useRef, useState } from "react"; -import { createParam } from "solito"; -import NativeVideo, { VideoProperties as VideoProps } from "react-native-video"; -import SubtitleOctopus from "libass-wasm"; -import Hls from "hls.js"; +import { Track, WatchItem } from "@kyoo/models"; +import { atom, useAtomValue, useSetAtom } from "jotai"; +import { useEffect, useLayoutEffect, useRef } from "react"; +import NativeVideo, { VideoProperties as VideoProps } from "./video"; import { bakedAtom } from "../jotai-utils"; import { Platform } from "react-native"; @@ -73,8 +70,6 @@ export const [privateFullscreen, fullscreenAtom] = bakedAtom( export const subtitleAtom = atom(null); -let hls: Hls | null = null; - export const Video = ({ links, setError, @@ -153,7 +148,6 @@ export const Video = ({ setBuffered(progress.playableDuration); }} onLoad={(info) => { - console.log(info); setDuration(info.duration); }} selectedTextTrack={ diff --git a/front/packages/ui/src/player/video.tsx b/front/packages/ui/src/player/video.tsx new file mode 100644 index 00000000..26f0f7b5 --- /dev/null +++ b/front/packages/ui/src/player/video.tsx @@ -0,0 +1,24 @@ +/* + * Kyoo - A portable and vast media library solution. + * Copyright (c) Kyoo. + * + * See AUTHORS.md and LICENSE file in the project root for full license information. + * + * Kyoo is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * Kyoo is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Kyoo. If not, see . + */ + +export * from "react-native-video"; + +import Video from "react-native-video"; +export default Video; diff --git a/front/packages/ui/src/player/video.web.tsx b/front/packages/ui/src/player/video.web.tsx new file mode 100644 index 00000000..5e2faa01 --- /dev/null +++ b/front/packages/ui/src/player/video.web.tsx @@ -0,0 +1,90 @@ +/* + * Kyoo - A portable and vast media library solution. + * Copyright (c) Kyoo. + * + * See AUTHORS.md and LICENSE file in the project root for full license information. + * + * Kyoo is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * Kyoo is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Kyoo. If not, see . + */ + +import { forwardRef, useEffect, useImperativeHandle, useRef } from "react"; +import { VideoProperties } from "react-native-video"; +import { useYoshiki } from "yoshiki"; +// import SubtitleOctopus from "libass-wasm"; +// import Hls from "hls.js"; + +// let hls: Hls | null = null; + +// TODO fallback via links and hls. +// TODO: Subtitle (vtt, srt and ass) + +const Video = forwardRef<{ seek: (value: number) => void }, VideoProperties>(function _Video( + { source, paused, muted, volume, onBuffer, onLoad, onProgress, onError }, + forwaredRef, +) { + const ref = useRef(null); + const { css } = useYoshiki(); + + useImperativeHandle( + forwaredRef, + () => ({ + seek: (value: number) => { + if (ref.current) ref.current.currentTime = value; + }, + }), + [], + ); + + useEffect(() => { + if (paused) ref.current?.pause(); + else ref.current?.play(); + }, [paused]); + useEffect(() => { + if (!ref.current || !volume) return; + ref.current.volume = Math.max(0, Math.min(volume, 100)) / 100; + }, [volume]); + + return ( +