mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Move android specific code to android specific file
This commit is contained in:
parent
479d3e9f07
commit
1e55b7bf50
@ -18,12 +18,11 @@
|
||||
* along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Track, WatchItem, Font, getToken } from "@kyoo/models";
|
||||
import { Track, WatchItem, Font } from "@kyoo/models";
|
||||
import { atom, useAtom, useAtomValue, useSetAtom } from "jotai";
|
||||
import { ElementRef, memo, useEffect, useLayoutEffect, useRef, useState } from "react";
|
||||
import NativeVideo, { VideoProperties as VideoProps } from "./video";
|
||||
import { Platform } from "react-native";
|
||||
import uuid from "react-native-uuid";
|
||||
|
||||
export const playAtom = atom(true);
|
||||
export const loadAtom = atom(false);
|
||||
@ -75,8 +74,6 @@ const privateFullscreen = atom(false);
|
||||
|
||||
export const subtitleAtom = atom<Track | null>(null);
|
||||
|
||||
let clientId = uuid.v4() as string;
|
||||
|
||||
export const Video = memo(function _Video({
|
||||
links,
|
||||
setError,
|
||||
@ -88,7 +85,6 @@ export const Video = memo(function _Video({
|
||||
fonts?: Font[];
|
||||
} & Partial<VideoProps>) {
|
||||
const ref = useRef<ElementRef<typeof NativeVideo> | null>(null);
|
||||
const token = useRef<string | null>(null);
|
||||
const [isPlaying, setPlay] = useAtom(playAtom);
|
||||
const setLoad = useSetAtom(loadAtom);
|
||||
const [source, setSource] = useState<string | null>(null);
|
||||
@ -112,13 +108,6 @@ export const Video = memo(function _Video({
|
||||
setPlay(true);
|
||||
}, [mode, links, setLoad, setPrivateProgress, setPublicProgress, setPlay]);
|
||||
|
||||
useEffect(() => {
|
||||
async function run() {
|
||||
token.current = await getToken();
|
||||
}
|
||||
run();
|
||||
}, [links]);
|
||||
|
||||
const volume = useAtomValue(volumeAtom);
|
||||
const isMuted = useAtomValue(mutedAtom);
|
||||
|
||||
@ -142,10 +131,6 @@ export const Video = memo(function _Video({
|
||||
source={{
|
||||
uri: source,
|
||||
...links,
|
||||
headers: {
|
||||
Authorization: `Bearer: ${token.current}`,
|
||||
"X-CLIENT-ID": clientId,
|
||||
},
|
||||
}}
|
||||
paused={!isPlaying}
|
||||
muted={isMuted}
|
||||
@ -167,16 +152,16 @@ export const Video = memo(function _Video({
|
||||
selectedTextTrack={
|
||||
subtitle
|
||||
? {
|
||||
type: "index",
|
||||
value: subtitle.trackIndex,
|
||||
}
|
||||
type: "index",
|
||||
value: subtitle.trackIndex,
|
||||
}
|
||||
: { type: "disabled" }
|
||||
}
|
||||
fonts={fonts}
|
||||
onMediaUnsupported={() => {
|
||||
if (mode == PlayMode.Direct) setPlayMode(PlayMode.Hls);
|
||||
}}
|
||||
// TODO: textTracks: external subtitles
|
||||
// TODO: textTracks: external subtitles
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
@ -31,29 +31,47 @@ declare module "react-native-video" {
|
||||
|
||||
export * from "react-native-video";
|
||||
|
||||
import { Font } from "@kyoo/models";
|
||||
import { Font, getToken } from "@kyoo/models";
|
||||
import { IconButton, Menu } from "@kyoo/primitives";
|
||||
import { ComponentProps, forwardRef } from "react";
|
||||
import { ComponentProps, forwardRef, useEffect, useRef } from "react";
|
||||
import { atom, useAtom, useAtomValue, useSetAtom } from "jotai";
|
||||
import NativeVideo, { OnLoadData } from "react-native-video";
|
||||
import NativeVideo, { OnLoadData, VideoProps } from "react-native-video";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { PlayMode, playModeAtom } from "./state";
|
||||
import uuid from "react-native-uuid";
|
||||
|
||||
const infoAtom = atom<OnLoadData | null>(null);
|
||||
const videoAtom = atom(0);
|
||||
const audioAtom = atom(0);
|
||||
|
||||
const Video = forwardRef<NativeVideo, ComponentProps<typeof NativeVideo>>(function _NativeVideo(
|
||||
{ onLoad, ...props },
|
||||
const clientId = uuid.v4() as string;
|
||||
|
||||
const Video = forwardRef<NativeVideo, VideoProps>(function _NativeVideo(
|
||||
{ onLoad, source, ...props },
|
||||
ref,
|
||||
) {
|
||||
const token = useRef<string | null>(null);
|
||||
const setInfo = useSetAtom(infoAtom);
|
||||
const video = useAtomValue(videoAtom);
|
||||
const audio = useAtomValue(audioAtom);
|
||||
|
||||
useEffect(() => {
|
||||
async function run() {
|
||||
token.current = await getToken();
|
||||
}
|
||||
run();
|
||||
}, [source]);
|
||||
|
||||
return (
|
||||
<NativeVideo
|
||||
ref={ref}
|
||||
source={{
|
||||
...source,
|
||||
headers: {
|
||||
Authorization: `Bearer: ${token.current}`,
|
||||
"X-CLIENT-ID": clientId,
|
||||
}
|
||||
}}
|
||||
onLoad={(info) => {
|
||||
setInfo(info);
|
||||
onLoad?.(info);
|
||||
|
Loading…
x
Reference in New Issue
Block a user