import type { HybridView, HybridViewProps, HybridViewMethods, } from 'react-native-nitro-modules'; import type { ResizeMode, SurfaceType, FullscreenConfig, VideoSource, VideoTrackSelection, SubtitleTrackSelection, AudioTrackSelection, } from './types.nitro'; import type { PlaybackEngine } from './PlaybackEngine.nitro'; /** * Props for the VideoView — set from React. */ export interface VideoViewProps extends HybridViewProps { /** How the video should be scaled within the view bounds. Default 'contain'. */ resizeMode: ResizeMode; /** Enable Picture-in-Picture. Default false. */ pipEnabled: boolean; /** * Keep the video's audio playing when the app is backgrounded. Default false. * * iOS: detaches the AVPlayerLayer while backgrounded so playback continues as * audio-only (requires the `audio` UIBackgroundMode in the host app's * Info.plist), then reattaches on foreground. Ignored while PiP is active. */ playInBackground: boolean; /** Called when PiP starts. */ onPipStart: () => void; /** Called when PiP stops. */ onPipStop: () => void; /** * The type of rendering surface to use (Android only). * - 'surfaceView' (default): Dedicated surface, best performance, but doesn't * support View animations/transforms. * - 'textureView': Renders through GPU composition pipeline, supports View * animations/transforms but slightly slower. */ surfaceType: SurfaceType; /** Called when fullscreen mode is entered. */ onFullscreenEnter: () => void; /** Called when fullscreen mode is exited. */ onFullscreenExit: () => void; /** Video track selection. Controls which video track/resolution is used. */ selectedVideoTrack: VideoTrackSelection; /** Subtitle track selection. Controls which subtitle/caption track is displayed. */ selectedSubtitleTrack: SubtitleTrackSelection; /** Audio track selection. Controls which audio track is used. */ selectedAudioTrack: AudioTrackSelection; /** * VAST/VMAP ad tag URL. When set and an AdsController is registered via * `enableIMAds()`, the native view intercepts the engine's `ready` state * and runs the pre-roll sequence before content plays. Set to an empty * string to disable ads on this view. */ adTagUrl: string; /** * Media source to load automatically when set. * The native view creates a MediaItem and calls load() (or loadAndPlay() * when autoPlay is true) on the attached engine. */ source: VideoSource; /** * When true, the source is loaded and playback starts automatically. * When false, the source is loaded but playback must be started manually. * Default: true. */ autoPlay: boolean; } /** * Methods for the VideoView — called via hybridRef. */ export interface VideoViewMethods extends HybridViewMethods { /** Attach a PlaybackEngine to render its video output. */ attachEngine(engine: PlaybackEngine): void; /** Detach the current engine. Video surface goes blank. */ detachEngine(): void; /** Programmatically start Picture-in-Picture. */ startPictureInPicture(): void; /** Programmatically stop Picture-in-Picture. */ stopPictureInPicture(): void; /** Enter fullscreen mode. On iOS: presents modal AVPlayerViewController. On Android: expands to Activity window with system UI hidden. */ enterFullscreen(config?: FullscreenConfig): void; /** Exit fullscreen mode. Returns to inline playback. */ exitFullscreen(): void; /** Whether the view is currently in fullscreen mode. */ isFullscreen(): boolean; /** * Enter native fullscreen using AVPlayerViewController (iOS only). * Presents a system-provided fullscreen player with built-in controls: * scrubber, AirPlay button, subtitle selection, and a dismiss button. * On Android this is a no-op — use enterFullscreen() instead. * * On dismiss, playback auto-resumes if it was playing (AVPlayerViewController * pauses briefly on dismiss — this is an AVKit constraint, not a bug). */ enterNativeFullscreen(): void; /** * Apply video track selection imperatively. * Workaround: Fabric's CachedProp does not propagate struct props * on RN 0.84+, so these methods bypass the prop bridge. */ applyVideoTrack(selection: VideoTrackSelection): void; /** Apply subtitle track selection imperatively. */ applySubtitleTrack(selection: SubtitleTrackSelection): void; /** Apply audio track selection imperatively. */ applyAudioTrack(selection: AudioTrackSelection): void; } /** * VideoView renders video content from a PlaybackEngine. * * The PlaybackEngine handles all playback logic. This component * only provides a rendering surface (AVPlayerLayer on iOS, * SurfaceView on Android). * * Unmounting VideoView does NOT stop playback — audio continues. */ export type VideoView = HybridView;