Create types for player & view

This commit is contained in:
2026-04-09 12:52:54 +02:00
parent c71c8fb8f9
commit e1e2fa3f3b
70 changed files with 3499 additions and 369 deletions
-10
View File
@@ -1,10 +0,0 @@
import { getHostComponent, type HybridRef } from "react-native-nitro-modules";
import OmniConfig from "../nitrogen/generated/shared/json/OmniConfig.json";
import type { OmniMethods, OmniProps } from "./specs/omni.nitro";
export const Omni = getHostComponent<OmniProps, OmniMethods>(
"Omni",
() => OmniConfig,
);
export type OmniRef = HybridRef<OmniProps, OmniMethods>;
+25
View File
@@ -0,0 +1,25 @@
import { createContext, type ReactNode, useContext } from "react";
import { NitroModules } from "react-native-nitro-modules";
import type {
OmniPlayerFactory,
OmniPlayerProps,
} from "./specs/omni-player.nitro";
import type { OmniPlayer } from "./types/player";
const ProviderFactory = NitroModules.createHybridObject<OmniPlayerFactory>(
"OmniProviderFactory",
);
const PlayerCtx = createContext<OmniPlayer>(null!);
export const OmniProvider = ({
children,
...props
}: OmniPlayerProps & { children: ReactNode }) => {
const player = ProviderFactory.createPlayer(props);
return <PlayerCtx.Provider value={player}>{children}</PlayerCtx.Provider>;
};
export const usePlayer = () => {
return useContext(PlayerCtx);
};
+15
View File
@@ -0,0 +1,15 @@
import type { HybridObject } from "react-native-nitro-modules";
import type { OmniPlayer as OmniPlayerT } from "../types/player";
import type { OmniPlayerProps as OmniPlayerPropsT } from "../types/provider";
export interface OmniPlayerProps
extends HybridObject<{ android: "kotlin" }>,
OmniPlayerPropsT {}
export interface OmniPlayer
extends HybridObject<{ android: "kotlin" }>,
OmniPlayerT {}
export interface OmniPlayerFactory extends HybridObject<{ android: "kotlin" }> {
createPlayer(props: OmniPlayerProps): OmniPlayer;
}
+14
View File
@@ -0,0 +1,14 @@
import type {
HybridView,
HybridViewMethods,
HybridViewProps,
} from "react-native-nitro-modules";
import type { OmniViewProps } from "../types/view";
export interface Props extends HybridViewProps, OmniViewProps {}
export type OmniView = HybridView<
Props,
HybridViewMethods,
{ android: "kotlin" }
>;
-13
View File
@@ -1,13 +0,0 @@
import type {
HybridView,
HybridViewMethods,
HybridViewProps,
} from "react-native-nitro-modules";
export interface OmniProps extends HybridViewProps {
isRed: boolean;
}
export interface OmniMethods extends HybridViewMethods {}
export type Omni = HybridView<OmniProps, OmniMethods, { android: "kotlin" }>;
+3
View File
@@ -0,0 +1,3 @@
export interface OmniEvents {
onEnd: () => void;
}
+46
View File
@@ -0,0 +1,46 @@
export interface OmniPlayer {
play(): void;
pause(): void;
seekBy(offset: number): void;
// trigger the prev/next event manually, the user has to implement the event
playPrev(): void;
playNext(): void;
readonly hasPrev: boolean;
readonly hasNext: boolean;
readonly status: PlayerStatus;
readonly isPlaying: boolean;
currentTime: number;
readonly buffered: number;
readonly duration: number;
playbackRate: number;
// between 0 and 1
volume: number;
readonly videos: Track[];
selectVideo(video: Track): void;
readonly audios: Track[];
selectAudio(audio: Track): void;
readonly subtitles: Track[];
selectSubtitle(subtitle: Track): void;
readonly rendition: Rendition[];
selectRendition(rendition: Rendition | null): void;
}
export type PlayerStatus = "idle" | "loading" | "readyToPlay" | "error";
export interface Track {
id: string;
label?: string;
language?: string;
selected: boolean;
}
export interface Rendition {
id: string;
width: number;
height: number;
bitrate: number;
selected: boolean;
}
+35
View File
@@ -0,0 +1,35 @@
export interface OmniPlayerProps {
src: VideoSrc[];
startTime?: number;
subtitles: Subtitle[];
metadata?: Metadata;
mixAudio?: MixAudioMode;
}
export interface VideoSrc {
uri: string;
mimeType?: string;
// header sends with xhr requests (especially useful for HLS)
// might not be available depending on browser/platform.
headers: Record<string, string>;
}
export interface Subtitle {
id: string;
link: string;
mimeType?: string;
language?: string;
label?: string;
}
export interface Metadata {
title: string;
album?: string;
artist?: string;
imageLink?: string;
// if one of those is true, the prev/next button will be there and a `onPrevSelected` even will be fired.
hasPrev?: boolean;
hasNext?: boolean;
}
export type MixAudioMode = "mixWithOthers" | "doNotMix" | "duckOthers" | "auto";
+5
View File
@@ -0,0 +1,5 @@
export interface OmniViewProps {
autoplay?: boolean;
showNotification?: boolean;
autoPip?: boolean;
}
+10
View File
@@ -0,0 +1,10 @@
import { getHostComponent, type HybridRef, type HybridViewMethods } from "react-native-nitro-modules";
import OmniConfig from "../nitrogen/generated/shared/json/OmniViewConfig.json";
import type { Props } from "./specs/omni-view.nitro";
export const OmniView = getHostComponent<Props, HybridViewMethods>(
"OmniView",
() => OmniConfig,
);
export type OmnViewiRef = HybridRef<Props, HybridViewMethods>;