2023-10-06 10:39:14 -06:00
|
|
|
import React, {
|
|
|
|
useState,
|
|
|
|
useCallback,
|
|
|
|
useMemo,
|
|
|
|
useRef,
|
|
|
|
forwardRef,
|
|
|
|
useImperativeHandle,
|
|
|
|
type ComponentRef,
|
2023-10-07 04:56:35 -06:00
|
|
|
} from 'react';
|
2024-04-03 12:49:47 -06:00
|
|
|
import {
|
|
|
|
View,
|
|
|
|
StyleSheet,
|
|
|
|
Image,
|
|
|
|
Platform,
|
|
|
|
type StyleProp,
|
|
|
|
type ImageStyle,
|
|
|
|
type NativeSyntheticEvent,
|
|
|
|
} from 'react-native';
|
|
|
|
|
2023-10-26 00:46:04 -06:00
|
|
|
import NativeVideoComponent, {
|
2024-03-07 03:35:17 -07:00
|
|
|
type OnAudioFocusChangedData,
|
|
|
|
type OnAudioTracksData,
|
|
|
|
type OnBandwidthUpdateData,
|
|
|
|
type OnBufferData,
|
|
|
|
type OnExternalPlaybackChangeData,
|
|
|
|
type OnGetLicenseData,
|
|
|
|
type OnLoadStartData,
|
|
|
|
type OnPictureInPictureStatusChangedData,
|
|
|
|
type OnPlaybackStateChangedData,
|
|
|
|
type OnProgressData,
|
|
|
|
type OnSeekData,
|
|
|
|
type OnTextTrackDataChangedData,
|
|
|
|
type OnTimedMetadataData,
|
|
|
|
type OnVideoAspectRatioData,
|
|
|
|
type OnVideoErrorData,
|
|
|
|
type OnVideoTracksData,
|
2023-10-26 00:46:04 -06:00
|
|
|
type VideoComponentType,
|
2024-03-07 03:35:17 -07:00
|
|
|
type VideoSrc,
|
|
|
|
} from './specs/VideoNativeComponent';
|
|
|
|
import {
|
|
|
|
generateHeaderForNative,
|
|
|
|
getReactTag,
|
|
|
|
resolveAssetSourceForVideo,
|
|
|
|
} from './utils';
|
|
|
|
import {VideoManager} from './specs/VideoNativeComponent';
|
2024-04-03 12:49:47 -06:00
|
|
|
import type {
|
|
|
|
OnLoadData,
|
|
|
|
OnTextTracksData,
|
|
|
|
OnReceiveAdEventData,
|
|
|
|
ReactVideoProps,
|
|
|
|
} from './types';
|
2023-10-07 04:56:35 -06:00
|
|
|
|
2023-10-26 00:46:04 -06:00
|
|
|
export type VideoSaveData = {
|
|
|
|
uri: string;
|
|
|
|
};
|
2023-10-06 10:39:14 -06:00
|
|
|
|
|
|
|
export interface VideoRef {
|
|
|
|
seek: (time: number, tolerance?: number) => void;
|
|
|
|
resume: () => void;
|
|
|
|
pause: () => void;
|
|
|
|
presentFullscreenPlayer: () => void;
|
|
|
|
dismissFullscreenPlayer: () => void;
|
2023-10-07 04:56:35 -06:00
|
|
|
restoreUserInterfaceForPictureInPictureStopCompleted: (
|
|
|
|
restore: boolean,
|
|
|
|
) => void;
|
2023-11-13 13:36:16 -07:00
|
|
|
save: (options: object) => Promise<VideoSaveData>;
|
2024-05-20 04:21:48 -06:00
|
|
|
setVolume: (volume: number) => void;
|
2023-10-06 10:39:14 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
const Video = forwardRef<VideoRef, ReactVideoProps>(
|
|
|
|
(
|
|
|
|
{
|
|
|
|
source,
|
|
|
|
style,
|
|
|
|
resizeMode,
|
|
|
|
posterResizeMode,
|
|
|
|
poster,
|
|
|
|
fullscreen,
|
|
|
|
drm,
|
|
|
|
textTracks,
|
2023-10-11 14:15:58 -06:00
|
|
|
selectedVideoTrack,
|
2023-10-06 10:39:14 -06:00
|
|
|
selectedAudioTrack,
|
|
|
|
selectedTextTrack,
|
|
|
|
onLoadStart,
|
|
|
|
onLoad,
|
|
|
|
onError,
|
|
|
|
onProgress,
|
|
|
|
onSeek,
|
|
|
|
onEnd,
|
|
|
|
onBuffer,
|
|
|
|
onBandwidthUpdate,
|
|
|
|
onExternalPlaybackChange,
|
|
|
|
onFullscreenPlayerWillPresent,
|
|
|
|
onFullscreenPlayerDidPresent,
|
|
|
|
onFullscreenPlayerWillDismiss,
|
|
|
|
onFullscreenPlayerDidDismiss,
|
|
|
|
onReadyForDisplay,
|
|
|
|
onPlaybackRateChange,
|
2023-11-04 11:11:54 -06:00
|
|
|
onVolumeChange,
|
2023-10-06 10:39:14 -06:00
|
|
|
onAudioBecomingNoisy,
|
|
|
|
onPictureInPictureStatusChanged,
|
|
|
|
onRestoreUserInterfaceForPictureInPictureStop,
|
|
|
|
onReceiveAdEvent,
|
|
|
|
onPlaybackStateChanged,
|
|
|
|
onAudioFocusChanged,
|
|
|
|
onIdle,
|
|
|
|
onTimedMetadata,
|
|
|
|
onAudioTracks,
|
|
|
|
onTextTracks,
|
2024-02-29 06:41:04 -07:00
|
|
|
onTextTrackDataChanged,
|
2023-10-06 10:39:14 -06:00
|
|
|
onVideoTracks,
|
2023-10-26 00:46:04 -06:00
|
|
|
onAspectRatio,
|
2023-10-06 10:39:14 -06:00
|
|
|
...rest
|
|
|
|
},
|
2023-10-07 04:56:35 -06:00
|
|
|
ref,
|
2023-10-06 10:39:14 -06:00
|
|
|
) => {
|
|
|
|
const nativeRef = useRef<ComponentRef<VideoComponentType>>(null);
|
|
|
|
const [showPoster, setShowPoster] = useState(!!poster);
|
|
|
|
const [isFullscreen, setIsFullscreen] = useState(fullscreen);
|
|
|
|
const [
|
|
|
|
_restoreUserInterfaceForPIPStopCompletionHandler,
|
|
|
|
setRestoreUserInterfaceForPIPStopCompletionHandler,
|
|
|
|
] = useState<boolean | undefined>();
|
|
|
|
|
2024-04-05 02:35:57 -06:00
|
|
|
const hasPoster = !!poster;
|
|
|
|
|
2023-10-06 10:39:14 -06:00
|
|
|
const posterStyle = useMemo<StyleProp<ImageStyle>>(
|
|
|
|
() => ({
|
|
|
|
...StyleSheet.absoluteFillObject,
|
|
|
|
resizeMode:
|
2023-10-07 04:56:35 -06:00
|
|
|
posterResizeMode && posterResizeMode !== 'none'
|
2023-10-06 10:39:14 -06:00
|
|
|
? posterResizeMode
|
2023-10-07 04:56:35 -06:00
|
|
|
: 'contain',
|
2023-10-06 10:39:14 -06:00
|
|
|
}),
|
2023-10-07 04:56:35 -06:00
|
|
|
[posterResizeMode],
|
2023-10-06 10:39:14 -06:00
|
|
|
);
|
|
|
|
|
2024-03-07 03:35:17 -07:00
|
|
|
const src = useMemo<VideoSrc | undefined>(() => {
|
2023-10-07 04:56:35 -06:00
|
|
|
if (!source) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2023-10-06 10:39:14 -06:00
|
|
|
const resolvedSource = resolveAssetSourceForVideo(source);
|
2023-10-07 04:56:35 -06:00
|
|
|
let uri = resolvedSource.uri || '';
|
|
|
|
if (uri && uri.match(/^\//)) {
|
|
|
|
uri = `file://${uri}`;
|
|
|
|
}
|
|
|
|
if (!uri) {
|
2023-10-26 00:46:04 -06:00
|
|
|
console.log('Trying to load empty source');
|
2023-10-07 04:56:35 -06:00
|
|
|
}
|
2024-04-16 02:41:39 -06:00
|
|
|
const isNetwork = !!(uri && uri.match(/^(rtp|rtsp|http|https):/));
|
2023-10-06 10:39:14 -06:00
|
|
|
const isAsset = !!(
|
|
|
|
uri &&
|
|
|
|
uri.match(
|
2023-10-07 04:56:35 -06:00
|
|
|
/^(assets-library|ipod-library|file|content|ms-appx|ms-appdata):/,
|
2023-10-06 10:39:14 -06:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
|
|
|
uri,
|
|
|
|
isNetwork,
|
|
|
|
isAsset,
|
|
|
|
shouldCache: resolvedSource.shouldCache || false,
|
2023-10-07 04:56:35 -06:00
|
|
|
type: resolvedSource.type || '',
|
2023-10-06 10:39:14 -06:00
|
|
|
mainVer: resolvedSource.mainVer || 0,
|
|
|
|
patchVer: resolvedSource.patchVer || 0,
|
2024-03-07 03:35:17 -07:00
|
|
|
requestHeaders: generateHeaderForNative(resolvedSource.headers),
|
2023-11-24 04:52:46 -07:00
|
|
|
startPosition: resolvedSource.startPosition ?? -1,
|
|
|
|
cropStart: resolvedSource.cropStart || 0,
|
|
|
|
cropEnd: resolvedSource.cropEnd,
|
2024-05-07 04:30:57 -06:00
|
|
|
metadata: resolvedSource.metadata,
|
2023-10-06 10:39:14 -06:00
|
|
|
};
|
|
|
|
}, [source]);
|
|
|
|
|
|
|
|
const _drm = useMemo(() => {
|
2023-10-07 04:56:35 -06:00
|
|
|
if (!drm) {
|
|
|
|
return;
|
|
|
|
}
|
2023-10-11 14:15:58 -06:00
|
|
|
|
2023-10-06 10:39:14 -06:00
|
|
|
return {
|
2023-10-11 14:15:58 -06:00
|
|
|
type: drm.type,
|
2023-10-06 10:39:14 -06:00
|
|
|
licenseServer: drm.licenseServer,
|
2024-03-07 03:35:17 -07:00
|
|
|
headers: generateHeaderForNative(drm.headers),
|
2023-10-06 10:39:14 -06:00
|
|
|
contentId: drm.contentId,
|
|
|
|
certificateUrl: drm.certificateUrl,
|
|
|
|
base64Certificate: drm.base64Certificate,
|
|
|
|
useExternalGetLicense: !!drm.getLicense,
|
|
|
|
};
|
|
|
|
}, [drm]);
|
|
|
|
|
|
|
|
const _selectedTextTrack = useMemo(() => {
|
2023-10-07 04:56:35 -06:00
|
|
|
if (!selectedTextTrack) {
|
|
|
|
return;
|
|
|
|
}
|
2024-04-30 07:12:37 -06:00
|
|
|
const type = typeof selectedTextTrack.value;
|
|
|
|
if (type !== 'number' && type !== 'string') {
|
|
|
|
console.log('invalid type provided to selectedTextTrack');
|
|
|
|
return;
|
|
|
|
}
|
2023-10-06 10:39:14 -06:00
|
|
|
return {
|
2023-10-11 14:15:58 -06:00
|
|
|
type: selectedTextTrack?.type,
|
2024-04-30 07:12:37 -06:00
|
|
|
value: `${selectedTextTrack.value}`,
|
2023-10-07 04:56:35 -06:00
|
|
|
};
|
2023-10-06 10:39:14 -06:00
|
|
|
}, [selectedTextTrack]);
|
|
|
|
|
|
|
|
const _selectedAudioTrack = useMemo(() => {
|
2023-10-07 04:56:35 -06:00
|
|
|
if (!selectedAudioTrack) {
|
|
|
|
return;
|
|
|
|
}
|
2024-04-30 07:12:37 -06:00
|
|
|
const type = typeof selectedAudioTrack.value;
|
|
|
|
if (type !== 'number' && type !== 'string') {
|
|
|
|
console.log('invalid type provided to selectedAudioTrack');
|
|
|
|
return;
|
|
|
|
}
|
2023-10-11 14:15:58 -06:00
|
|
|
|
2023-10-06 10:39:14 -06:00
|
|
|
return {
|
2023-10-11 14:15:58 -06:00
|
|
|
type: selectedAudioTrack?.type,
|
2024-04-30 07:12:37 -06:00
|
|
|
value: `${selectedAudioTrack.value}`,
|
2023-10-07 04:56:35 -06:00
|
|
|
};
|
2023-10-06 10:39:14 -06:00
|
|
|
}, [selectedAudioTrack]);
|
|
|
|
|
2023-10-11 14:15:58 -06:00
|
|
|
const _selectedVideoTrack = useMemo(() => {
|
|
|
|
if (!selectedVideoTrack) {
|
|
|
|
return;
|
|
|
|
}
|
2024-05-22 06:01:55 -06:00
|
|
|
const type = typeof selectedVideoTrack.value;
|
|
|
|
if (type !== 'number' && type !== 'string') {
|
|
|
|
console.log('invalid type provided to selectedVideoTrack');
|
|
|
|
return;
|
|
|
|
}
|
2023-10-11 14:15:58 -06:00
|
|
|
return {
|
|
|
|
type: selectedVideoTrack?.type,
|
2024-05-22 06:01:55 -06:00
|
|
|
value: `${selectedVideoTrack.value}`,
|
2023-10-11 14:15:58 -06:00
|
|
|
};
|
|
|
|
}, [selectedVideoTrack]);
|
|
|
|
|
2023-10-07 04:56:35 -06:00
|
|
|
const seek = useCallback(async (time: number, tolerance?: number) => {
|
2024-05-21 14:15:47 -06:00
|
|
|
if (isNaN(time) || time === null) {
|
|
|
|
throw new Error("Specified time is not a number: '" + time + "'");
|
2023-10-07 04:56:35 -06:00
|
|
|
}
|
2023-10-06 10:39:14 -06:00
|
|
|
|
2023-10-07 04:56:35 -06:00
|
|
|
if (!nativeRef.current) {
|
|
|
|
console.warn('Video Component is not mounted');
|
|
|
|
return;
|
|
|
|
}
|
2023-10-06 10:39:14 -06:00
|
|
|
|
2024-03-28 04:22:04 -06:00
|
|
|
const callSeekFunction = () => {
|
|
|
|
VideoManager.seek(
|
|
|
|
{
|
|
|
|
time,
|
|
|
|
tolerance: tolerance || 0,
|
|
|
|
},
|
|
|
|
getReactTag(nativeRef),
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-10-07 04:56:35 -06:00
|
|
|
Platform.select({
|
2024-03-28 04:22:04 -06:00
|
|
|
ios: callSeekFunction,
|
|
|
|
android: callSeekFunction,
|
2023-10-07 04:56:35 -06:00
|
|
|
default: () => {
|
2024-03-28 04:22:04 -06:00
|
|
|
// TODO: Implement VideoManager.seek for windows
|
|
|
|
nativeRef.current?.setNativeProps({seek: time});
|
2023-10-07 04:56:35 -06:00
|
|
|
},
|
|
|
|
})();
|
|
|
|
}, []);
|
2023-10-06 10:39:14 -06:00
|
|
|
|
|
|
|
const presentFullscreenPlayer = useCallback(() => {
|
|
|
|
setIsFullscreen(true);
|
|
|
|
}, [setIsFullscreen]);
|
|
|
|
|
|
|
|
const dismissFullscreenPlayer = useCallback(() => {
|
|
|
|
setIsFullscreen(false);
|
|
|
|
}, [setIsFullscreen]);
|
|
|
|
|
2023-11-13 13:36:16 -07:00
|
|
|
const save = useCallback((options: object) => {
|
2023-12-10 07:53:48 -07:00
|
|
|
// VideoManager.save can be null on android & windows
|
|
|
|
return VideoManager.save?.(options, getReactTag(nativeRef));
|
2023-10-06 10:39:14 -06:00
|
|
|
}, []);
|
|
|
|
|
2023-10-26 00:46:04 -06:00
|
|
|
const pause = useCallback(() => {
|
|
|
|
return VideoManager.setPlayerPauseState(true, getReactTag(nativeRef));
|
2023-10-06 10:39:14 -06:00
|
|
|
}, []);
|
|
|
|
|
2023-10-26 00:46:04 -06:00
|
|
|
const resume = useCallback(() => {
|
|
|
|
return VideoManager.setPlayerPauseState(false, getReactTag(nativeRef));
|
2023-10-06 10:39:14 -06:00
|
|
|
}, []);
|
|
|
|
|
|
|
|
const restoreUserInterfaceForPictureInPictureStopCompleted = useCallback(
|
|
|
|
(restored: boolean) => {
|
|
|
|
setRestoreUserInterfaceForPIPStopCompletionHandler(restored);
|
|
|
|
},
|
2023-10-07 04:56:35 -06:00
|
|
|
[setRestoreUserInterfaceForPIPStopCompletionHandler],
|
2023-10-06 10:39:14 -06:00
|
|
|
);
|
|
|
|
|
2024-05-20 04:21:48 -06:00
|
|
|
const setVolume = useCallback((volume: number) => {
|
|
|
|
return VideoManager.setVolume(volume, getReactTag(nativeRef));
|
|
|
|
}, []);
|
|
|
|
|
2023-10-06 10:39:14 -06:00
|
|
|
const onVideoLoadStart = useCallback(
|
|
|
|
(e: NativeSyntheticEvent<OnLoadStartData>) => {
|
2024-04-05 02:35:57 -06:00
|
|
|
hasPoster && setShowPoster(true);
|
2023-10-06 10:39:14 -06:00
|
|
|
onLoadStart?.(e.nativeEvent);
|
|
|
|
},
|
2024-04-05 02:35:57 -06:00
|
|
|
[hasPoster, onLoadStart],
|
2023-10-06 10:39:14 -06:00
|
|
|
);
|
|
|
|
|
|
|
|
const onVideoLoad = useCallback(
|
|
|
|
(e: NativeSyntheticEvent<OnLoadData>) => {
|
2023-10-07 04:56:35 -06:00
|
|
|
if (Platform.OS === 'windows') {
|
2024-04-05 02:35:57 -06:00
|
|
|
hasPoster && setShowPoster(false);
|
2023-10-07 04:56:35 -06:00
|
|
|
}
|
2023-10-06 10:39:14 -06:00
|
|
|
onLoad?.(e.nativeEvent);
|
|
|
|
},
|
2024-04-05 02:35:57 -06:00
|
|
|
[onLoad, hasPoster, setShowPoster],
|
2023-10-06 10:39:14 -06:00
|
|
|
);
|
|
|
|
|
|
|
|
const onVideoError = useCallback(
|
|
|
|
(e: NativeSyntheticEvent<OnVideoErrorData>) => {
|
|
|
|
onError?.(e.nativeEvent);
|
|
|
|
},
|
2023-10-07 04:56:35 -06:00
|
|
|
[onError],
|
2023-10-06 10:39:14 -06:00
|
|
|
);
|
|
|
|
|
|
|
|
const onVideoProgress = useCallback(
|
|
|
|
(e: NativeSyntheticEvent<OnProgressData>) => {
|
|
|
|
onProgress?.(e.nativeEvent);
|
|
|
|
},
|
2023-10-07 04:56:35 -06:00
|
|
|
[onProgress],
|
2023-10-06 10:39:14 -06:00
|
|
|
);
|
|
|
|
|
|
|
|
const onVideoSeek = useCallback(
|
|
|
|
(e: NativeSyntheticEvent<OnSeekData>) => {
|
|
|
|
onSeek?.(e.nativeEvent);
|
|
|
|
},
|
2023-10-07 04:56:35 -06:00
|
|
|
[onSeek],
|
2023-10-06 10:39:14 -06:00
|
|
|
);
|
|
|
|
|
2023-10-07 04:56:35 -06:00
|
|
|
const onVideoPlaybackStateChanged = useCallback(
|
|
|
|
(e: NativeSyntheticEvent<OnPlaybackStateChangedData>) => {
|
|
|
|
onPlaybackStateChanged?.(e.nativeEvent);
|
|
|
|
},
|
|
|
|
[onPlaybackStateChanged],
|
|
|
|
);
|
2023-10-06 10:39:14 -06:00
|
|
|
|
|
|
|
// android only
|
|
|
|
const _onTimedMetadata = useCallback(
|
|
|
|
(e: NativeSyntheticEvent<OnTimedMetadataData>) => {
|
|
|
|
onTimedMetadata?.(e.nativeEvent);
|
|
|
|
},
|
2023-10-07 04:56:35 -06:00
|
|
|
[onTimedMetadata],
|
2023-10-06 10:39:14 -06:00
|
|
|
);
|
|
|
|
|
2023-10-07 04:56:35 -06:00
|
|
|
const _onAudioTracks = useCallback(
|
|
|
|
(e: NativeSyntheticEvent<OnAudioTracksData>) => {
|
|
|
|
onAudioTracks?.(e.nativeEvent);
|
|
|
|
},
|
|
|
|
[onAudioTracks],
|
|
|
|
);
|
2023-10-06 10:39:14 -06:00
|
|
|
|
2023-10-07 04:56:35 -06:00
|
|
|
const _onTextTracks = useCallback(
|
|
|
|
(e: NativeSyntheticEvent<OnTextTracksData>) => {
|
|
|
|
onTextTracks?.(e.nativeEvent);
|
|
|
|
},
|
|
|
|
[onTextTracks],
|
|
|
|
);
|
2023-10-06 10:39:14 -06:00
|
|
|
|
2024-02-29 06:41:04 -07:00
|
|
|
const _onTextTrackDataChanged = useCallback(
|
|
|
|
(
|
|
|
|
e: NativeSyntheticEvent<OnTextTrackDataChangedData & {target?: number}>,
|
|
|
|
) => {
|
|
|
|
const {...eventData} = e.nativeEvent;
|
|
|
|
delete eventData.target;
|
|
|
|
onTextTrackDataChanged?.(eventData as OnTextTrackDataChangedData);
|
|
|
|
},
|
|
|
|
[onTextTrackDataChanged],
|
|
|
|
);
|
|
|
|
|
2023-10-07 04:56:35 -06:00
|
|
|
const _onVideoTracks = useCallback(
|
|
|
|
(e: NativeSyntheticEvent<OnVideoTracksData>) => {
|
|
|
|
onVideoTracks?.(e.nativeEvent);
|
|
|
|
},
|
|
|
|
[onVideoTracks],
|
|
|
|
);
|
2023-10-06 10:39:14 -06:00
|
|
|
|
|
|
|
const _onPlaybackRateChange = useCallback(
|
2023-10-07 04:56:35 -06:00
|
|
|
(e: NativeSyntheticEvent<Readonly<{playbackRate: number}>>) => {
|
2023-10-06 10:39:14 -06:00
|
|
|
onPlaybackRateChange?.(e.nativeEvent);
|
|
|
|
},
|
2023-10-07 04:56:35 -06:00
|
|
|
[onPlaybackRateChange],
|
2023-10-06 10:39:14 -06:00
|
|
|
);
|
|
|
|
|
2023-11-04 11:11:54 -06:00
|
|
|
const _onVolumeChange = useCallback(
|
|
|
|
(e: NativeSyntheticEvent<Readonly<{volume: number}>>) => {
|
|
|
|
onVolumeChange?.(e.nativeEvent);
|
|
|
|
},
|
|
|
|
[onVolumeChange],
|
|
|
|
);
|
|
|
|
|
2023-10-06 10:39:14 -06:00
|
|
|
const _onReadyForDisplay = useCallback(() => {
|
2024-04-05 02:35:57 -06:00
|
|
|
hasPoster && setShowPoster(false);
|
2023-10-06 10:39:14 -06:00
|
|
|
onReadyForDisplay?.();
|
2024-04-05 02:35:57 -06:00
|
|
|
}, [setShowPoster, hasPoster, onReadyForDisplay]);
|
2023-10-06 10:39:14 -06:00
|
|
|
|
|
|
|
const _onPictureInPictureStatusChanged = useCallback(
|
|
|
|
(e: NativeSyntheticEvent<OnPictureInPictureStatusChangedData>) => {
|
|
|
|
onPictureInPictureStatusChanged?.(e.nativeEvent);
|
|
|
|
},
|
2023-10-07 04:56:35 -06:00
|
|
|
[onPictureInPictureStatusChanged],
|
2023-10-06 10:39:14 -06:00
|
|
|
);
|
|
|
|
|
2023-10-07 04:56:35 -06:00
|
|
|
const _onAudioFocusChanged = useCallback(
|
|
|
|
(e: NativeSyntheticEvent<OnAudioFocusChangedData>) => {
|
|
|
|
onAudioFocusChanged?.(e.nativeEvent);
|
|
|
|
},
|
|
|
|
[onAudioFocusChanged],
|
|
|
|
);
|
2023-10-06 10:39:14 -06:00
|
|
|
|
2023-10-07 04:56:35 -06:00
|
|
|
const onVideoBuffer = useCallback(
|
|
|
|
(e: NativeSyntheticEvent<OnBufferData>) => {
|
|
|
|
onBuffer?.(e.nativeEvent);
|
|
|
|
},
|
|
|
|
[onBuffer],
|
|
|
|
);
|
2023-10-06 10:39:14 -06:00
|
|
|
|
2023-10-07 04:56:35 -06:00
|
|
|
const onVideoExternalPlaybackChange = useCallback(
|
|
|
|
(e: NativeSyntheticEvent<OnExternalPlaybackChangeData>) => {
|
|
|
|
onExternalPlaybackChange?.(e.nativeEvent);
|
|
|
|
},
|
|
|
|
[onExternalPlaybackChange],
|
|
|
|
);
|
2023-10-06 10:39:14 -06:00
|
|
|
|
2023-10-07 04:56:35 -06:00
|
|
|
const _onBandwidthUpdate = useCallback(
|
|
|
|
(e: NativeSyntheticEvent<OnBandwidthUpdateData>) => {
|
|
|
|
onBandwidthUpdate?.(e.nativeEvent);
|
|
|
|
},
|
|
|
|
[onBandwidthUpdate],
|
|
|
|
);
|
2023-10-06 10:39:14 -06:00
|
|
|
|
2023-10-07 04:56:35 -06:00
|
|
|
const _onReceiveAdEvent = useCallback(
|
|
|
|
(e: NativeSyntheticEvent<OnReceiveAdEventData>) => {
|
|
|
|
onReceiveAdEvent?.(e.nativeEvent);
|
|
|
|
},
|
|
|
|
[onReceiveAdEvent],
|
|
|
|
);
|
2023-10-06 10:39:14 -06:00
|
|
|
|
2023-10-26 00:46:04 -06:00
|
|
|
const _onVideoAspectRatio = useCallback(
|
|
|
|
(e: NativeSyntheticEvent<OnVideoAspectRatioData>) => {
|
|
|
|
onAspectRatio?.(e.nativeEvent);
|
|
|
|
},
|
|
|
|
[onAspectRatio],
|
|
|
|
);
|
|
|
|
|
2024-03-28 04:22:52 -06:00
|
|
|
const useExternalGetLicense = drm?.getLicense instanceof Function;
|
|
|
|
|
2023-10-06 10:39:14 -06:00
|
|
|
const onGetLicense = useCallback(
|
|
|
|
(event: NativeSyntheticEvent<OnGetLicenseData>) => {
|
2024-03-28 04:22:52 -06:00
|
|
|
if (useExternalGetLicense) {
|
2023-10-06 10:39:14 -06:00
|
|
|
const data = event.nativeEvent;
|
|
|
|
if (data && data.spcBase64) {
|
2023-10-07 04:56:35 -06:00
|
|
|
const getLicenseOverride = drm.getLicense(
|
|
|
|
data.spcBase64,
|
|
|
|
data.contentId,
|
|
|
|
data.licenseUrl,
|
2024-03-12 09:47:49 -06:00
|
|
|
data.loadedLicenseUrl,
|
2023-10-07 04:56:35 -06:00
|
|
|
);
|
2023-10-06 10:39:14 -06:00
|
|
|
const getLicensePromise = Promise.resolve(getLicenseOverride); // Handles both scenarios, getLicenseOverride being a promise and not.
|
2023-10-07 04:56:35 -06:00
|
|
|
getLicensePromise
|
|
|
|
.then((result) => {
|
|
|
|
if (result !== undefined) {
|
|
|
|
nativeRef.current &&
|
|
|
|
VideoManager.setLicenseResult(
|
|
|
|
result,
|
2024-03-12 09:47:49 -06:00
|
|
|
data.loadedLicenseUrl,
|
2023-10-07 04:56:35 -06:00
|
|
|
getReactTag(nativeRef),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
nativeRef.current &&
|
|
|
|
VideoManager.setLicenseResultError(
|
|
|
|
'Empty license result',
|
2024-03-12 09:47:49 -06:00
|
|
|
data.loadedLicenseUrl,
|
2023-10-07 04:56:35 -06:00
|
|
|
getReactTag(nativeRef),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
nativeRef.current &&
|
|
|
|
VideoManager.setLicenseResultError(
|
|
|
|
'fetch error',
|
2024-03-12 09:47:49 -06:00
|
|
|
data.loadedLicenseUrl,
|
2023-10-07 04:56:35 -06:00
|
|
|
getReactTag(nativeRef),
|
|
|
|
);
|
|
|
|
});
|
2023-10-06 10:39:14 -06:00
|
|
|
} else {
|
2023-10-07 04:56:35 -06:00
|
|
|
VideoManager.setLicenseResultError(
|
|
|
|
'No spc received',
|
2024-03-12 09:47:49 -06:00
|
|
|
data.loadedLicenseUrl,
|
2023-10-07 04:56:35 -06:00
|
|
|
getReactTag(nativeRef),
|
|
|
|
);
|
2023-10-06 10:39:14 -06:00
|
|
|
}
|
|
|
|
}
|
2023-10-07 04:56:35 -06:00
|
|
|
},
|
2024-03-28 04:22:52 -06:00
|
|
|
[drm, useExternalGetLicense],
|
2023-10-06 10:39:14 -06:00
|
|
|
);
|
|
|
|
|
|
|
|
useImperativeHandle(
|
|
|
|
ref,
|
|
|
|
() => ({
|
|
|
|
seek,
|
|
|
|
presentFullscreenPlayer,
|
|
|
|
dismissFullscreenPlayer,
|
|
|
|
save,
|
|
|
|
pause,
|
|
|
|
resume,
|
|
|
|
restoreUserInterfaceForPictureInPictureStopCompleted,
|
2024-05-20 04:21:48 -06:00
|
|
|
setVolume,
|
2023-10-06 10:39:14 -06:00
|
|
|
}),
|
|
|
|
[
|
|
|
|
seek,
|
|
|
|
presentFullscreenPlayer,
|
|
|
|
dismissFullscreenPlayer,
|
|
|
|
save,
|
|
|
|
pause,
|
|
|
|
resume,
|
|
|
|
restoreUserInterfaceForPictureInPictureStopCompleted,
|
2024-05-20 04:21:48 -06:00
|
|
|
setVolume,
|
2023-10-07 04:56:35 -06:00
|
|
|
],
|
2023-10-06 10:39:14 -06:00
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<View style={style}>
|
|
|
|
<NativeVideoComponent
|
|
|
|
ref={nativeRef}
|
|
|
|
{...rest}
|
|
|
|
src={src}
|
|
|
|
drm={_drm}
|
|
|
|
style={StyleSheet.absoluteFill}
|
2023-10-11 13:56:54 -06:00
|
|
|
resizeMode={resizeMode}
|
2023-10-06 10:39:14 -06:00
|
|
|
fullscreen={isFullscreen}
|
|
|
|
restoreUserInterfaceForPIPStopCompletionHandler={
|
|
|
|
_restoreUserInterfaceForPIPStopCompletionHandler
|
|
|
|
}
|
|
|
|
textTracks={textTracks}
|
|
|
|
selectedTextTrack={_selectedTextTrack}
|
|
|
|
selectedAudioTrack={_selectedAudioTrack}
|
2023-10-11 14:15:58 -06:00
|
|
|
selectedVideoTrack={_selectedVideoTrack}
|
2024-03-28 04:22:52 -06:00
|
|
|
onGetLicense={useExternalGetLicense ? onGetLicense : undefined}
|
2024-05-07 03:06:12 -06:00
|
|
|
onVideoLoad={
|
|
|
|
onLoad || hasPoster
|
|
|
|
? (onVideoLoad as (e: NativeSyntheticEvent<object>) => void)
|
|
|
|
: undefined
|
|
|
|
}
|
|
|
|
onVideoLoadStart={
|
|
|
|
onLoadStart || hasPoster ? onVideoLoadStart : undefined
|
|
|
|
}
|
|
|
|
onVideoError={onError ? onVideoError : undefined}
|
|
|
|
onVideoProgress={onProgress ? onVideoProgress : undefined}
|
|
|
|
onVideoSeek={onSeek ? onVideoSeek : undefined}
|
2023-10-06 10:39:14 -06:00
|
|
|
onVideoEnd={onEnd}
|
2024-05-07 03:06:12 -06:00
|
|
|
onVideoBuffer={onBuffer ? onVideoBuffer : undefined}
|
|
|
|
onVideoPlaybackStateChanged={
|
2024-05-10 12:38:34 -06:00
|
|
|
onPlaybackStateChanged ? onVideoPlaybackStateChanged : undefined
|
2024-05-07 03:06:12 -06:00
|
|
|
}
|
|
|
|
onVideoBandwidthUpdate={
|
|
|
|
onBandwidthUpdate ? _onBandwidthUpdate : undefined
|
|
|
|
}
|
|
|
|
onTimedMetadata={onTimedMetadata ? _onTimedMetadata : undefined}
|
|
|
|
onAudioTracks={onAudioTracks ? _onAudioTracks : undefined}
|
|
|
|
onTextTracks={onTextTracks ? _onTextTracks : undefined}
|
|
|
|
onTextTrackDataChanged={
|
|
|
|
onTextTrackDataChanged ? _onTextTrackDataChanged : undefined
|
|
|
|
}
|
|
|
|
onVideoTracks={onVideoTracks ? _onVideoTracks : undefined}
|
2023-10-06 10:39:14 -06:00
|
|
|
onVideoFullscreenPlayerDidDismiss={onFullscreenPlayerDidDismiss}
|
|
|
|
onVideoFullscreenPlayerDidPresent={onFullscreenPlayerDidPresent}
|
|
|
|
onVideoFullscreenPlayerWillDismiss={onFullscreenPlayerWillDismiss}
|
|
|
|
onVideoFullscreenPlayerWillPresent={onFullscreenPlayerWillPresent}
|
2024-05-07 03:06:12 -06:00
|
|
|
onVideoExternalPlaybackChange={
|
|
|
|
onExternalPlaybackChange ? onVideoExternalPlaybackChange : undefined
|
|
|
|
}
|
|
|
|
onVideoIdle={onIdle}
|
|
|
|
onAudioFocusChanged={
|
|
|
|
onAudioFocusChanged ? _onAudioFocusChanged : undefined
|
|
|
|
}
|
2024-05-14 05:04:44 -06:00
|
|
|
onReadyForDisplay={
|
|
|
|
onReadyForDisplay || hasPoster ? _onReadyForDisplay : undefined
|
|
|
|
}
|
2024-05-07 03:06:12 -06:00
|
|
|
onPlaybackRateChange={
|
|
|
|
onPlaybackRateChange ? _onPlaybackRateChange : undefined
|
|
|
|
}
|
|
|
|
onVolumeChange={onVolumeChange ? _onVolumeChange : undefined}
|
2023-10-06 10:39:14 -06:00
|
|
|
onVideoAudioBecomingNoisy={onAudioBecomingNoisy}
|
2024-05-07 03:06:12 -06:00
|
|
|
onPictureInPictureStatusChanged={
|
|
|
|
onPictureInPictureStatusChanged
|
|
|
|
? _onPictureInPictureStatusChanged
|
|
|
|
: undefined
|
|
|
|
}
|
2023-10-06 10:39:14 -06:00
|
|
|
onRestoreUserInterfaceForPictureInPictureStop={
|
|
|
|
onRestoreUserInterfaceForPictureInPictureStop
|
|
|
|
}
|
2024-05-07 03:06:12 -06:00
|
|
|
onVideoAspectRatio={onAspectRatio ? _onVideoAspectRatio : undefined}
|
2024-04-03 12:49:47 -06:00
|
|
|
onReceiveAdEvent={
|
2024-05-07 03:06:12 -06:00
|
|
|
onReceiveAdEvent
|
|
|
|
? (_onReceiveAdEvent as (e: NativeSyntheticEvent<object>) => void)
|
|
|
|
: undefined
|
2024-04-03 12:49:47 -06:00
|
|
|
}
|
2023-10-06 10:39:14 -06:00
|
|
|
/>
|
2024-04-05 02:35:57 -06:00
|
|
|
{hasPoster && showPoster ? (
|
2023-10-07 04:56:35 -06:00
|
|
|
<Image style={posterStyle} source={{uri: poster}} />
|
2023-10-06 10:39:14 -06:00
|
|
|
) : null}
|
|
|
|
</View>
|
|
|
|
);
|
2023-10-07 04:56:35 -06:00
|
|
|
},
|
2023-10-06 10:39:14 -06:00
|
|
|
);
|
|
|
|
|
2023-10-07 04:56:35 -06:00
|
|
|
Video.displayName = 'Video';
|
|
|
|
export default Video;
|