chore(android): rework view type (#3940)
This commit is contained in:
@@ -44,11 +44,12 @@ import {
|
||||
resolveAssetSourceForVideo,
|
||||
} from './utils';
|
||||
import {VideoManager} from './specs/VideoNativeComponent';
|
||||
import type {
|
||||
OnLoadData,
|
||||
OnTextTracksData,
|
||||
OnReceiveAdEventData,
|
||||
ReactVideoProps,
|
||||
import {
|
||||
type OnLoadData,
|
||||
type OnTextTracksData,
|
||||
type OnReceiveAdEventData,
|
||||
type ReactVideoProps,
|
||||
ViewType,
|
||||
} from './types';
|
||||
|
||||
export type VideoSaveData = {
|
||||
@@ -84,6 +85,9 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
|
||||
selectedVideoTrack,
|
||||
selectedAudioTrack,
|
||||
selectedTextTrack,
|
||||
useTextureView,
|
||||
useSecureView,
|
||||
viewType,
|
||||
onLoadStart,
|
||||
onLoad,
|
||||
onError,
|
||||
@@ -571,6 +575,37 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
|
||||
],
|
||||
);
|
||||
|
||||
const _viewType = useMemo(() => {
|
||||
const hasValidDrmProp =
|
||||
drm !== undefined && Object.keys(drm).length !== 0;
|
||||
|
||||
const shallForceViewType =
|
||||
hasValidDrmProp && (viewType === ViewType.TEXTURE || useTextureView);
|
||||
|
||||
if (shallForceViewType) {
|
||||
console.warn(
|
||||
'cannot use DRM on texture view. please set useTextureView={false}',
|
||||
);
|
||||
}
|
||||
if (useSecureView && useTextureView) {
|
||||
console.warn(
|
||||
'cannot use SecureView on texture view. please set useTextureView={false}',
|
||||
);
|
||||
}
|
||||
|
||||
return shallForceViewType
|
||||
? useSecureView
|
||||
? ViewType.SURFACE_SECURE
|
||||
: ViewType.SURFACE // check if we should force the type to Surface due to DRM
|
||||
: viewType
|
||||
? viewType // else use ViewType from source
|
||||
: useSecureView // else infer view type from useSecureView and useTextureView
|
||||
? ViewType.SURFACE_SECURE
|
||||
: useTextureView
|
||||
? ViewType.TEXTURE
|
||||
: ViewType.SURFACE;
|
||||
}, [drm, useSecureView, useTextureView, viewType]);
|
||||
|
||||
return (
|
||||
<View style={style}>
|
||||
<NativeVideoComponent
|
||||
@@ -651,6 +686,7 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
|
||||
onControlsVisibilityChange={
|
||||
onControlsVisibilityChange ? _onControlsVisibilityChange : undefined
|
||||
}
|
||||
viewType={_viewType}
|
||||
/>
|
||||
{hasPoster && showPoster ? (
|
||||
<Image style={posterStyle} source={{uri: poster}} />
|
||||
|
@@ -337,8 +337,7 @@ export interface VideoNativeProps extends ViewProps {
|
||||
minLoadRetryCount?: Int32; // Android
|
||||
reportBandwidth?: boolean; //Android
|
||||
subtitleStyle?: SubtitleStyle; // android
|
||||
useTextureView?: boolean; // Android
|
||||
useSecureView?: boolean; // Android
|
||||
viewType?: Int32; // Android
|
||||
bufferingStrategy?: BufferingStrategyType; // Android
|
||||
controlsStyles?: ControlsStyles; // Android
|
||||
onControlsVisibilityChange?: DirectEventHandler<OnControlsVisibilityChange>;
|
||||
|
11
src/types/ViewType.ts
Normal file
11
src/types/ViewType.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Define Available view type for android
|
||||
* these values shall match android spec, see ViewType.kt
|
||||
*/
|
||||
enum ResizeMode {
|
||||
TEXTURE = 0,
|
||||
SURFACE = 1,
|
||||
SURFACE_SECURE = 2,
|
||||
}
|
||||
|
||||
export default ResizeMode;
|
@@ -5,5 +5,6 @@ export * from './language';
|
||||
export {default as Orientation} from './Orientation';
|
||||
export {default as ResizeMode} from './ResizeMode';
|
||||
export {default as TextTrackType} from './TextTrackType';
|
||||
export {default as ViewType} from './ViewType';
|
||||
export * from './video';
|
||||
export * from '../specs/VideoNativeComponent';
|
||||
|
@@ -3,6 +3,7 @@ import type {ReactVideoEvents} from './events';
|
||||
import type {StyleProp, ViewProps, ViewStyle} from 'react-native';
|
||||
import type VideoResizeMode from './ResizeMode';
|
||||
import type FilterType from './FilterType';
|
||||
import type ViewType from './ViewType';
|
||||
|
||||
export type Headers = Record<string, string>;
|
||||
|
||||
@@ -256,8 +257,9 @@ export interface ReactVideoProps extends ReactVideoEvents, ViewProps {
|
||||
shutterColor?: string; // Android
|
||||
textTracks?: TextTracks;
|
||||
testID?: string;
|
||||
useTextureView?: boolean; // Android
|
||||
useSecureView?: boolean; // Android
|
||||
viewType?: ViewType;
|
||||
useTextureView?: boolean; // Android // deprecated
|
||||
useSecureView?: boolean; // Android // deprecated
|
||||
volume?: number;
|
||||
localSourceEncryptionKeyScheme?: string;
|
||||
debug?: DebugConfig;
|
||||
|
Reference in New Issue
Block a user