v3: added localization, use global player for uploaded audio/video files
This commit is contained in:
@@ -1,19 +1,43 @@
|
||||
import { createContext } from "react";
|
||||
|
||||
export interface PlayerItem {
|
||||
embedUrl: string;
|
||||
title?: string;
|
||||
type: string;
|
||||
}
|
||||
export type PlayerItem =
|
||||
| { kind: "embed"; embedUrl: string; title?: string; type: string }
|
||||
| { kind: "file"; fileUrl: string; mimeType: string; title?: string };
|
||||
|
||||
export interface PlayerContextValue {
|
||||
// Playback state — readable by any consumer
|
||||
current: PlayerItem | null;
|
||||
playing: boolean;
|
||||
currentTime: number;
|
||||
duration: number;
|
||||
|
||||
// Control — callable by any consumer
|
||||
play(item: PlayerItem): void;
|
||||
stop(): void;
|
||||
seekTo(time: number): void;
|
||||
togglePlay(): void;
|
||||
|
||||
// Internal: GlobalPlayer registers MediaPlayer's imperative handles here
|
||||
// so seekTo / togglePlay can reach into the actual media element.
|
||||
seekRef: { current: ((t: number) => void) | null };
|
||||
toggleRef: { current: (() => void) | null };
|
||||
|
||||
// Internal: GlobalPlayer calls these to push state back into the provider
|
||||
onPlayStateChange(playing: boolean): void;
|
||||
onTimeUpdate(time: number, duration: number): void;
|
||||
}
|
||||
|
||||
export const PlayerContext = createContext<PlayerContextValue>({
|
||||
current: null,
|
||||
playing: false,
|
||||
currentTime: 0,
|
||||
duration: 0,
|
||||
play: () => {},
|
||||
stop: () => {},
|
||||
seekTo: () => {},
|
||||
togglePlay: () => {},
|
||||
seekRef: { current: null },
|
||||
toggleRef: { current: null },
|
||||
onPlayStateChange: () => {},
|
||||
onTimeUpdate: () => {},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user