VideoView component is used to display video content from a VideoPlayer instance. It provides controls for fullscreen, picture-in-picture, and various display options.
Usage
- Basic
- With Controls
- With Ref & Events
- Picture in Picture
Props
player
The VideoPlayer instance to play the video. Create one using
useVideoPlayer.style
The style of the video view. Use React Native’s StyleSheet to define dimensions and other visual properties.
controls
Whether to show the native playback controls.
pictureInPicture
Whether to enable and show the picture in picture button in native controls.
autoEnterPictureInPicture
Whether to automatically enter picture in picture mode when the video is playing and the app goes to background.
resizeMode
How the video should be resized to fit the view:
'contain': Scale the video uniformly (maintain aspect ratio) so that it fits entirely within the view'cover': Scale the video uniformly (maintain aspect ratio) so that it fills the entire view (may crop)'stretch': Scale the video to fill the entire view without maintaining aspect ratio'none': Do not resize the video - it will fallback to default behavior (contain)
keepScreenAwake
Whether to keep the screen awake while the video view is mounted.
surfaceType
The type of underlying native view on Android:
'surface': Uses a SurfaceView. More performant, but cannot be animated or transformed.'texture': Uses a TextureView. Less performant, but can be animated and transformed.
Events
onFullscreenChange
Called when the video view’s fullscreen state changes.
onPictureInPictureChange
Called when the video view’s picture in picture state changes.
willEnterFullscreen
Called when the video view will enter fullscreen mode.
willExitFullscreen
Called when the video view will exit fullscreen mode.
willEnterPictureInPicture
Called when the video view will enter picture in picture mode.
willExitPictureInPicture
Called when the video view will exit picture in picture mode.
Ref Methods
TheVideoView component exposes several methods through a ref. Use useRef<VideoViewRef>() to access them.
enterFullscreen
Enter fullscreen mode.
exitFullscreen
Exit fullscreen mode.
enterPictureInPicture
Enter picture in picture mode.
exitPictureInPicture
Exit picture in picture mode.
canEnterPictureInPicture
Check if picture in picture mode is supported on the current device.Returns
true if picture in picture mode is supported, false otherwise.addEventListener
addEventListener
<Event extends keyof VideoViewEvents>(event: Event, callback: VideoViewEvents[Event]) => ListenerSubscription
Adds a listener for a view event. Returns a subscription object that can be used to remove the listener.Available events:
onPictureInPictureChangeonFullscreenChangewillEnterFullscreenwillExitFullscreenwillEnterPictureInPicturewillExitPictureInPicture
Related
- VideoPlayer - The player instance that controls video playback
- useVideoPlayer - Hook to create and manage a VideoPlayer instance
- useEvent - Hook to listen to player events