mirror of
https://github.com/zoriya/react-native-omni.git
synced 2026-08-09 07:36:39 +00:00
feat(android): allow both exoplayer and vlc
This commit is contained in:
@@ -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
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}) => {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -64,3 +64,9 @@ export interface Rendition {
|
||||
readonly bitrate: number;
|
||||
readonly selected: boolean;
|
||||
}
|
||||
|
||||
export type AndroidBackend = "vlc" | "exoplayer";
|
||||
|
||||
export interface PlayerBackend {
|
||||
android?: AndroidBackend;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user