feat(android): allow both exoplayer and vlc

This commit is contained in:
2026-07-26 13:26:56 +02:00
parent 7f733d8ef2
commit 6423ed0bc5
17 changed files with 418 additions and 21 deletions
+2
View File
@@ -2,9 +2,11 @@ export { useEvent, usePlayerState } from "./events";
export { OmniProvider, usePlayer } from "./provider";
export type { OmniEvents } from "./types/events";
export type {
AndroidBackend,
CastStatus,
OmniPlayer,
OmniPlayerState,
PlayerBackend,
PlayerStatus,
Rendition,
Track,
+6 -2
View File
@@ -1,7 +1,7 @@
import { createContext, type ReactNode, useContext, useEffect } from "react";
import { NitroModules } from "react-native-nitro-modules";
import type { OmniPlayerFactory } from "./specs/omni-player.nitro";
import type { OmniPlayer } from "./types/player";
import type { OmniPlayer, PlayerBackend } from "./types/player";
import type { CastOptions, Source } from "./types/source";
import { useLazyRef } from "./utils/lazy-ref";
@@ -13,15 +13,19 @@ const PlayerCtx = createContext<OmniPlayer>(null!);
export const OmniProvider = ({
children,
source,
backend = { android: "vlc" },
showNotification = false,
cast: _,
}: {
source?: Source;
cast?: CastOptions;
backend?: PlayerBackend;
children: ReactNode;
showNotification?: boolean;
}) => {
const player = useLazyRef(() => ProviderFactory.createPlayer(source));
const player = useLazyRef(() =>
ProviderFactory.createPlayer(source, backend),
);
useEffect(() => {
player.source = source;
+4 -1
View File
@@ -8,7 +8,7 @@ import {
useRef,
} from "react";
import { WebOmniPlayer } from "./player.web";
import type { OmniPlayer } from "./types/player";
import type { OmniPlayer, PlayerBackend } from "./types/player";
import type { CastOptions, Source } from "./types/source";
import { useLazyRef } from "./utils/lazy-ref";
@@ -20,10 +20,13 @@ export const OmniProvider = ({
children,
source,
cast,
// Web always uses video.js; accepted for API parity with native.
backend: _backend,
showNotification = false,
}: {
source?: Source;
cast?: CastOptions;
backend?: PlayerBackend;
children: ReactNode;
showNotification?: boolean;
}) => {
+2 -1
View File
@@ -3,6 +3,7 @@ import type { OmniEvents } from "../types/events";
import type {
OmniPlayerState,
OmniPlayer as OmniPlayerT,
PlayerBackend,
PlayerStatus,
} from "../types/player";
import type { Source } from "../types/source";
@@ -59,5 +60,5 @@ export interface OmniPlayer
}
export interface OmniPlayerFactory extends HybridObject<{ android: "kotlin" }> {
createPlayer(props?: Source): OmniPlayer;
createPlayer(props?: Source, backend?: PlayerBackend): OmniPlayer;
}
+6
View File
@@ -64,3 +64,9 @@ export interface Rendition {
readonly bitrate: number;
readonly selected: boolean;
}
export type AndroidBackend = "vlc" | "exoplayer";
export interface PlayerBackend {
android?: AndroidBackend;
}