2023-10-07 04:56:35 -06:00
|
|
|
import type {
|
|
|
|
HostComponent,
|
|
|
|
NativeSyntheticEvent,
|
|
|
|
ViewProps,
|
|
|
|
} from 'react-native';
|
|
|
|
import {NativeModules, requireNativeComponent} from 'react-native';
|
|
|
|
import {getViewManagerConfig} from './utils';
|
2023-10-06 10:39:14 -06:00
|
|
|
|
|
|
|
// -------- There are types for native component (future codegen) --------
|
|
|
|
// if you are looking for types for react component, see src/types/video.ts
|
|
|
|
|
2023-10-07 04:56:35 -06:00
|
|
|
type Headers = Record<string, string>;
|
2023-10-06 10:39:14 -06:00
|
|
|
|
|
|
|
type VideoSrc = Readonly<{
|
|
|
|
uri?: string;
|
|
|
|
isNetwork?: boolean;
|
|
|
|
isAsset?: boolean;
|
|
|
|
shouldCache?: boolean;
|
|
|
|
type?: string;
|
|
|
|
mainVer?: number;
|
|
|
|
patchVer?: number;
|
|
|
|
requestHeaders?: Headers;
|
|
|
|
startTime?: number;
|
|
|
|
endTime?: number;
|
2023-10-07 04:56:35 -06:00
|
|
|
}>;
|
|
|
|
|
|
|
|
export type Filter =
|
|
|
|
| 'None'
|
|
|
|
| 'CIColorInvert'
|
|
|
|
| 'CIColorMonochrome'
|
|
|
|
| 'CIColorPosterize'
|
|
|
|
| 'CIFalseColor'
|
|
|
|
| 'CIMaximumComponent'
|
|
|
|
| 'CIMinimumComponent'
|
|
|
|
| 'CIPhotoEffectChrome'
|
|
|
|
| 'CIPhotoEffectFade'
|
|
|
|
| 'CIPhotoEffectInstant'
|
|
|
|
| 'CIPhotoEffectMono'
|
|
|
|
| 'CIPhotoEffectNoir'
|
|
|
|
| 'CIPhotoEffectProcess'
|
|
|
|
| 'CIPhotoEffectTonal'
|
|
|
|
| 'CIPhotoEffectTransfer'
|
|
|
|
| 'CISepiaTone';
|
2023-10-06 10:39:14 -06:00
|
|
|
|
|
|
|
export type DrmType = 'widevine' | 'playready' | 'clearkey' | 'fairplay';
|
|
|
|
|
|
|
|
type Drm = Readonly<{
|
|
|
|
drmType?: DrmType;
|
|
|
|
licenseServer?: string;
|
|
|
|
headers?: Headers;
|
|
|
|
contentId?: string; // ios
|
|
|
|
certificateUrl?: string; // ios
|
|
|
|
base64Certificate?: boolean; // ios default: false
|
|
|
|
useExternalGetLicense?: boolean; // ios
|
2023-10-07 04:56:35 -06:00
|
|
|
}>;
|
2023-10-06 10:39:14 -06:00
|
|
|
|
2023-10-07 04:56:35 -06:00
|
|
|
type TextTracks = ReadonlyArray<
|
|
|
|
Readonly<{
|
|
|
|
title: string;
|
|
|
|
language: string;
|
|
|
|
type: string;
|
|
|
|
uri: string;
|
|
|
|
}>
|
|
|
|
>;
|
2023-10-06 10:39:14 -06:00
|
|
|
|
|
|
|
type TextTrackType = 'system' | 'disabled' | 'title' | 'language' | 'index';
|
|
|
|
|
|
|
|
type SelectedTextTrack = Readonly<{
|
|
|
|
selectedTextType: TextTrackType;
|
|
|
|
value?: string;
|
|
|
|
index?: number;
|
2023-10-07 04:56:35 -06:00
|
|
|
}>;
|
2023-10-06 10:39:14 -06:00
|
|
|
|
|
|
|
type AudioTrackType = 'system' | 'disabled' | 'title' | 'language' | 'index';
|
|
|
|
|
|
|
|
type SelectedAudioTrack = Readonly<{
|
|
|
|
selectedAudioType: AudioTrackType;
|
|
|
|
value?: string;
|
|
|
|
index?: number;
|
2023-10-07 04:56:35 -06:00
|
|
|
}>;
|
2023-10-06 10:39:14 -06:00
|
|
|
|
|
|
|
export type Seek = Readonly<{
|
|
|
|
time: number;
|
|
|
|
tolerance?: number;
|
2023-10-07 04:56:35 -06:00
|
|
|
}>;
|
2023-10-06 10:39:14 -06:00
|
|
|
|
|
|
|
type BufferConfig = Readonly<{
|
|
|
|
minBufferMs?: number;
|
|
|
|
maxBufferMs?: number;
|
|
|
|
bufferForPlaybackMs?: number;
|
|
|
|
bufferForPlaybackAfterRebufferMs?: number;
|
|
|
|
maxHeapAllocationPercent?: number;
|
|
|
|
minBackBufferMemoryReservePercent?: number;
|
|
|
|
minBufferMemoryReservePercent?: number;
|
2023-10-07 04:56:35 -06:00
|
|
|
}>;
|
2023-10-06 10:39:14 -06:00
|
|
|
|
|
|
|
type SelectedVideoTrack = Readonly<{
|
|
|
|
type: 'auto' | 'disabled' | 'resolution' | 'index';
|
|
|
|
value?: number;
|
2023-10-07 04:56:35 -06:00
|
|
|
}>;
|
2023-10-06 10:39:14 -06:00
|
|
|
|
|
|
|
type SubtitleStyle = Readonly<{
|
|
|
|
fontSize?: number;
|
|
|
|
paddingTop?: number;
|
|
|
|
paddingBottom?: number;
|
|
|
|
paddingLeft?: number;
|
|
|
|
paddingRight?: number;
|
2023-10-07 04:56:35 -06:00
|
|
|
}>;
|
2023-10-06 10:39:14 -06:00
|
|
|
|
|
|
|
export type OnLoadData = Readonly<{
|
|
|
|
currentTime: number;
|
|
|
|
duration: number;
|
|
|
|
naturalSize: Readonly<{
|
|
|
|
width: number;
|
|
|
|
height: number;
|
|
|
|
orientation: 'portrait' | 'landscape';
|
|
|
|
}>;
|
2023-10-07 04:56:35 -06:00
|
|
|
}>;
|
2023-10-06 10:39:14 -06:00
|
|
|
|
|
|
|
export type OnLoadStartData = Readonly<{
|
|
|
|
isNetwork: boolean;
|
|
|
|
type: string;
|
|
|
|
uri: string;
|
2023-10-07 04:56:35 -06:00
|
|
|
}>;
|
2023-10-06 10:39:14 -06:00
|
|
|
|
2023-10-07 04:56:35 -06:00
|
|
|
export type OnBufferData = Readonly<{isBuffering: boolean}>;
|
2023-10-06 10:39:14 -06:00
|
|
|
|
|
|
|
export type OnProgressData = Readonly<{
|
|
|
|
currentTime: number;
|
|
|
|
playableDuration: number;
|
|
|
|
seekableDuration: number;
|
2023-10-07 04:56:35 -06:00
|
|
|
}>;
|
2023-10-06 10:39:14 -06:00
|
|
|
|
|
|
|
export type OnBandwidthUpdateData = Readonly<{
|
|
|
|
bitrate: number;
|
|
|
|
}>;
|
|
|
|
|
|
|
|
export type OnSeekData = Readonly<{
|
|
|
|
currentTime: number;
|
|
|
|
seekTime: number;
|
|
|
|
finished: boolean;
|
2023-10-07 04:56:35 -06:00
|
|
|
}>;
|
2023-10-06 10:39:14 -06:00
|
|
|
|
|
|
|
export type OnPlaybackStateChangedData = Readonly<{
|
|
|
|
isPlaying: boolean;
|
2023-10-07 04:56:35 -06:00
|
|
|
}>;
|
2023-10-06 10:39:14 -06:00
|
|
|
|
|
|
|
export type OnTimedMetadataData = Readonly<{
|
2023-10-07 04:56:35 -06:00
|
|
|
metadata: ReadonlyArray<
|
|
|
|
Readonly<{
|
|
|
|
value?: string;
|
|
|
|
identifier: string;
|
|
|
|
}>
|
|
|
|
>;
|
|
|
|
}>;
|
2023-10-06 10:39:14 -06:00
|
|
|
|
|
|
|
export type OnAudioTracksData = Readonly<{
|
2023-10-07 04:56:35 -06:00
|
|
|
audioTracks: ReadonlyArray<
|
|
|
|
Readonly<{
|
|
|
|
index: number;
|
|
|
|
title?: string;
|
|
|
|
language?: string;
|
|
|
|
bitrate?: number;
|
|
|
|
type?: string;
|
|
|
|
selected?: boolean;
|
|
|
|
}>
|
|
|
|
>;
|
|
|
|
}>;
|
2023-10-06 10:39:14 -06:00
|
|
|
|
|
|
|
export type OnTextTracksData = Readonly<{
|
2023-10-07 04:56:35 -06:00
|
|
|
textTracks: ReadonlyArray<
|
|
|
|
Readonly<{
|
|
|
|
index: number;
|
|
|
|
title?: string;
|
|
|
|
language?: string;
|
|
|
|
/**
|
|
|
|
* iOS only supports VTT, Android supports all 3
|
|
|
|
*/
|
|
|
|
type?: 'srt' | 'ttml' | 'vtt';
|
|
|
|
selected?: boolean;
|
|
|
|
}>
|
|
|
|
>;
|
|
|
|
}>;
|
2023-10-06 10:39:14 -06:00
|
|
|
|
|
|
|
export type OnVideoTracksData = Readonly<{
|
2023-10-07 04:56:35 -06:00
|
|
|
videoTracks: ReadonlyArray<
|
|
|
|
Readonly<{
|
|
|
|
trackId: number;
|
|
|
|
codecs?: string;
|
|
|
|
width?: number;
|
|
|
|
height?: number;
|
|
|
|
bitrate?: number;
|
|
|
|
selected?: boolean;
|
|
|
|
}>
|
|
|
|
>;
|
|
|
|
}>;
|
2023-10-06 10:39:14 -06:00
|
|
|
|
|
|
|
export type OnPlaybackData = Readonly<{
|
|
|
|
playbackRate: number;
|
|
|
|
}>;
|
|
|
|
|
|
|
|
export type OnExternalPlaybackChangeData = Readonly<{
|
|
|
|
isExternalPlaybackActive: boolean;
|
2023-10-07 04:56:35 -06:00
|
|
|
}>;
|
2023-10-06 10:39:14 -06:00
|
|
|
|
|
|
|
export type OnGetLicenseData = Readonly<{
|
|
|
|
licenseUrl: string;
|
|
|
|
contentId: string;
|
|
|
|
spcBase64: string;
|
2023-10-07 04:56:35 -06:00
|
|
|
}>;
|
2023-10-06 10:39:14 -06:00
|
|
|
|
|
|
|
export type OnPictureInPictureStatusChangedData = Readonly<{
|
|
|
|
isActive: boolean;
|
2023-10-07 04:56:35 -06:00
|
|
|
}>;
|
2023-10-06 10:39:14 -06:00
|
|
|
|
|
|
|
export type OnReceiveAdEventData = Readonly<{
|
|
|
|
event: string;
|
2023-10-07 04:56:35 -06:00
|
|
|
}>;
|
2023-10-06 10:39:14 -06:00
|
|
|
|
|
|
|
export type OnVideoErrorData = Readonly<{
|
|
|
|
error: string;
|
2023-10-07 04:56:35 -06:00
|
|
|
}>;
|
2023-10-06 10:39:14 -06:00
|
|
|
|
|
|
|
export type OnAudioFocusChangedData = Readonly<{
|
|
|
|
hasFocus: boolean;
|
2023-10-07 04:56:35 -06:00
|
|
|
}>;
|
2023-10-06 10:39:14 -06:00
|
|
|
|
2023-10-07 04:56:35 -06:00
|
|
|
export type NativeVideoResizeMode = unknown;
|
2023-10-06 10:39:14 -06:00
|
|
|
export interface VideoNativeProps extends ViewProps {
|
|
|
|
src?: VideoSrc;
|
|
|
|
drm?: Drm;
|
|
|
|
adTagUrl?: string;
|
|
|
|
allowsExternalPlayback?: boolean; // ios, true
|
|
|
|
maxBitRate?: number;
|
|
|
|
resizeMode?: NativeVideoResizeMode;
|
|
|
|
repeat?: boolean;
|
2023-10-07 04:56:35 -06:00
|
|
|
automaticallyWaitsToMinimizeStalling?: boolean;
|
2023-10-06 10:39:14 -06:00
|
|
|
textTracks?: TextTracks;
|
|
|
|
selectedTextTrack?: SelectedTextTrack;
|
|
|
|
selectedAudioTrack?: SelectedAudioTrack;
|
|
|
|
paused?: boolean;
|
|
|
|
muted?: boolean;
|
|
|
|
controls?: boolean;
|
|
|
|
filter?: Filter;
|
|
|
|
filterEnabled?: boolean;
|
|
|
|
volume?: number; // default 1.0
|
|
|
|
playInBackground?: boolean;
|
|
|
|
preventsDisplaySleepDuringVideoPlayback?: boolean;
|
|
|
|
preferredForwardBufferDuration?: number; //ios, 0
|
|
|
|
playWhenInactive?: boolean; // ios, false
|
|
|
|
pictureInPicture?: boolean; // ios, false
|
|
|
|
ignoreSilentSwitch?: 'inherit' | 'ignore' | 'obey'; // ios, 'inherit'
|
|
|
|
mixWithOthers?: 'inherit' | 'mix' | 'duck'; // ios, 'inherit'
|
|
|
|
rate?: number;
|
|
|
|
fullscreen?: boolean; // ios, false
|
|
|
|
fullscreenAutorotate?: boolean;
|
|
|
|
fullscreenOrientation?: 'all' | 'landscape' | 'portrait';
|
|
|
|
progressUpdateInterval?: number;
|
|
|
|
restoreUserInterfaceForPIPStopCompletionHandler?: boolean;
|
|
|
|
localSourceEncryptionKeyScheme?: string;
|
|
|
|
|
|
|
|
backBufferDurationMs?: number; // Android
|
|
|
|
bufferConfig?: BufferConfig; // Android
|
|
|
|
contentStartTime?: number; // Android
|
|
|
|
currentPlaybackTime?: number; // Android
|
|
|
|
disableDisconnectError?: boolean; // Android
|
2023-10-07 04:56:35 -06:00
|
|
|
focusable?: boolean; // Android
|
2023-10-06 10:39:14 -06:00
|
|
|
hideShutterView?: boolean; // Android
|
2023-10-07 04:56:35 -06:00
|
|
|
minLoadRetryCount?: number; // Android
|
2023-10-06 10:39:14 -06:00
|
|
|
reportBandwidth?: boolean; //Android
|
|
|
|
selectedVideoTrack?: SelectedVideoTrack; // android
|
2023-10-07 04:56:35 -06:00
|
|
|
subtitleStyle?: SubtitleStyle; // android
|
2023-10-06 10:39:14 -06:00
|
|
|
trackId?: string; // Android
|
2023-10-07 04:56:35 -06:00
|
|
|
useTextureView?: boolean; // Android
|
|
|
|
useSecureView?: boolean; // Android
|
2023-10-06 10:39:14 -06:00
|
|
|
|
|
|
|
onVideoLoad?: (event: NativeSyntheticEvent<OnLoadData>) => void;
|
|
|
|
onVideoLoadStart?: (event: NativeSyntheticEvent<OnLoadStartData>) => void;
|
|
|
|
onVideoBuffer?: (event: NativeSyntheticEvent<OnBufferData>) => void;
|
|
|
|
onVideoError?: (event: NativeSyntheticEvent<OnVideoErrorData>) => void;
|
|
|
|
onVideoProgress?: (event: NativeSyntheticEvent<OnProgressData>) => void;
|
2023-10-07 04:56:35 -06:00
|
|
|
onBandwidthUpdate?: (
|
|
|
|
event: NativeSyntheticEvent<OnBandwidthUpdateData>,
|
|
|
|
) => void;
|
2023-10-06 10:39:14 -06:00
|
|
|
onVideoSeek?: (event: NativeSyntheticEvent<OnSeekData>) => void;
|
2023-10-07 04:56:35 -06:00
|
|
|
onVideoEnd?: (event: NativeSyntheticEvent<Readonly<object>>) => void; // all
|
|
|
|
onVideoAudioBecomingNoisy?: (
|
|
|
|
event: NativeSyntheticEvent<Readonly<object>>,
|
|
|
|
) => void;
|
|
|
|
onVideoFullscreenPlayerWillPresent?: (
|
|
|
|
event: NativeSyntheticEvent<Readonly<object>>,
|
|
|
|
) => void; // ios, android
|
|
|
|
onVideoFullscreenPlayerDidPresent?: (
|
|
|
|
event: NativeSyntheticEvent<Readonly<object>>,
|
|
|
|
) => void; // ios, android
|
|
|
|
onVideoFullscreenPlayerWillDismiss?: (
|
|
|
|
event: NativeSyntheticEvent<Readonly<object>>,
|
|
|
|
) => void; // ios, android
|
|
|
|
onVideoFullscreenPlayerDidDismiss?: (
|
|
|
|
event: NativeSyntheticEvent<Readonly<object>>,
|
|
|
|
) => void; // ios, android
|
|
|
|
onReadyForDisplay?: (event: NativeSyntheticEvent<Readonly<object>>) => void;
|
2023-10-06 10:39:14 -06:00
|
|
|
onPlaybackRateChange?: (event: NativeSyntheticEvent<OnPlaybackData>) => void; // all
|
2023-10-07 04:56:35 -06:00
|
|
|
onVideoExternalPlaybackChange?: (
|
|
|
|
event: NativeSyntheticEvent<OnExternalPlaybackChangeData>,
|
|
|
|
) => void;
|
2023-10-06 10:39:14 -06:00
|
|
|
onGetLicense?: (event: NativeSyntheticEvent<OnGetLicenseData>) => void;
|
2023-10-07 04:56:35 -06:00
|
|
|
onPictureInPictureStatusChanged?: (
|
|
|
|
event: NativeSyntheticEvent<OnPictureInPictureStatusChangedData>,
|
|
|
|
) => void;
|
|
|
|
onRestoreUserInterfaceForPictureInPictureStop?: (
|
|
|
|
event: NativeSyntheticEvent<Readonly<object>>,
|
|
|
|
) => void;
|
|
|
|
onReceiveAdEvent?: (
|
|
|
|
event: NativeSyntheticEvent<OnReceiveAdEventData>,
|
|
|
|
) => void;
|
|
|
|
onVideoPlaybackStateChanged?: (
|
|
|
|
event: NativeSyntheticEvent<OnPlaybackStateChangedData>,
|
|
|
|
) => void; // android only
|
|
|
|
onVideoIdle?: (event: NativeSyntheticEvent<object>) => void; // android only (nowhere in document, so do not use as props. just type declaration)
|
|
|
|
onAudioFocusChanged?: (
|
|
|
|
event: NativeSyntheticEvent<OnAudioFocusChangedData>,
|
|
|
|
) => void; // android only (nowhere in document, so do not use as props. just type declaration)
|
2023-10-06 10:39:14 -06:00
|
|
|
onTimedMetadata?: (event: NativeSyntheticEvent<OnTimedMetadataData>) => void; // ios, android
|
|
|
|
onAudioTracks?: (event: NativeSyntheticEvent<OnAudioTracksData>) => void; // android
|
|
|
|
onTextTracks?: (event: NativeSyntheticEvent<OnTextTracksData>) => void; // android
|
|
|
|
onVideoTracks?: (event: NativeSyntheticEvent<OnVideoTracksData>) => void; // android
|
|
|
|
}
|
|
|
|
|
|
|
|
export type VideoComponentType = HostComponent<VideoNativeProps>;
|
|
|
|
|
|
|
|
export interface VideoManagerType {
|
|
|
|
save: (reactTag: number) => Promise<void>;
|
|
|
|
setPlayerPauseState: (paused: boolean, reactTag: number) => Promise<void>;
|
2023-10-07 04:56:35 -06:00
|
|
|
setLicenseResult: (
|
|
|
|
result: string,
|
|
|
|
licenseUrl: string,
|
|
|
|
reactTag: number,
|
|
|
|
) => Promise<void>;
|
|
|
|
setLicenseResultError: (
|
|
|
|
error: string,
|
|
|
|
licenseUrl: string,
|
|
|
|
reactTag: number,
|
|
|
|
) => Promise<void>;
|
2023-10-06 10:39:14 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface VideoDecoderPropertiesType {
|
|
|
|
getWidevineLevel: () => Promise<number>;
|
2023-10-07 04:56:35 -06:00
|
|
|
isCodecSupported: (
|
|
|
|
mimeType: string,
|
|
|
|
width: number,
|
|
|
|
height: number,
|
|
|
|
) => Promise<'unsupported' | 'hardware' | 'software'>;
|
2023-10-06 10:39:14 -06:00
|
|
|
isHEVCSupported: () => Promise<'unsupported' | 'hardware' | 'software'>;
|
|
|
|
}
|
|
|
|
|
|
|
|
export type VideoViewManagerConfig = {
|
|
|
|
Constants: {
|
2023-10-07 04:56:35 -06:00
|
|
|
ScaleNone: unknown;
|
|
|
|
ScaleToFill: unknown;
|
|
|
|
ScaleAspectFit: unknown;
|
|
|
|
ScaleAspectFill: unknown;
|
2023-10-06 10:39:14 -06:00
|
|
|
};
|
2023-10-07 04:56:35 -06:00
|
|
|
Commands: {[key: string]: number};
|
2023-10-06 10:39:14 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
export const VideoManager = NativeModules.VideoManager as VideoManagerType;
|
2023-10-07 04:56:35 -06:00
|
|
|
export const VideoDecoderProperties =
|
|
|
|
NativeModules.VideoDecoderProperties as VideoDecoderPropertiesType;
|
|
|
|
export const RCTVideoConstants = (
|
|
|
|
getViewManagerConfig('RCTVideo') as VideoViewManagerConfig
|
|
|
|
).Constants;
|
|
|
|
|
|
|
|
export default requireNativeComponent<VideoNativeProps>(
|
|
|
|
'RCTVideo',
|
|
|
|
) as VideoComponentType;
|