BNA

BNA UI
26

A video player component with custom controls, gestures, and subtitle support.

Installation

pnpm dlx bna-ui add video

Usage

import { Video } from '@/components/ui/video';
<Video
  source={{ uri: 'https://example.com/video.mp4' }}
  autoPlay={true}
  showControls={true}
/>

Examples

Default

Native Controls

Custom Controls

With Subtitles

Autoplay & Loop

Different Sources

Gesture Controls

Content Fit Options

API Reference

Video

The main video player component with customizable controls and features.

PropTypeDefaultDescription
sourceVideoSource-The video source (required).
styleViewStyle-Additional styles for the video container.
seekBynumber2Seconds to seek by on double tap.
autoPlaybooleanfalseWhether to auto-play the video.
loopbooleanfalseWhether to loop the video.
mutedbooleanfalseWhether to start muted.
nativeControlsbooleanfalseUse native video controls instead of custom ones.
showControlsbooleantrueWhether to show custom controls.
allowsFullscreenbooleantrueAllow fullscreen mode.
allowsPictureInPicturebooleantrueAllow picture-in-picture mode.
contentFit'contain' | 'cover' | 'fill''cover'How the video should fit within its container.
onLoad() => void-Callback when video is loaded.
onError(error: any) => void-Callback when an error occurs.
onPlaybackStatusUpdate(status: any) => void-Callback for playback status updates.
onFullscreenUpdate(isFullscreen: boolean) => void-Callback when fullscreen state changes.
subtitlesArray<Subtitle>[]Array of subtitle objects.

VideoRef

Reference methods available on the Video component.

MethodTypeDescription
play() => voidStart playing the video.
pause() => voidPause the video.
seekTo(seconds: number) => voidSeek to a specific time in seconds.
setVolume(volume: number) => voidSet the volume (0-1).
getCurrentTime() => numberGet the current playback time.
getDuration() => numberGet the total duration of the video.
isPlaying() => booleanCheck if the video is currently playing.
isMuted() => booleanCheck if the video is muted.

Subtitle

Subtitle object structure for the subtitles prop.

PropertyTypeDescription
startnumberStart time in seconds for the subtitle.
endnumberEnd time in seconds for the subtitle.
textstringThe subtitle text to display.

Gestures

The Video component supports several gesture interactions:

  • Single tap (center): Play/pause toggle
  • Single tap (left side): Seek backward by seekBy seconds
  • Single tap (right side): Seek forward by seekBy seconds
  • Progress bar tap: Seek to specific position

Features

Custom Controls

  • Play/pause button with visual feedback
  • Progress bar with seek functionality
  • Time display (current/total)
  • Mute/unmute toggle
  • Auto-hide controls after 3 seconds

Subtitle Support

  • Display subtitles based on current playback time
  • Customizable subtitle styling
  • Automatic subtitle timing

Error Handling

  • Graceful error handling with fallbacks
  • Console logging for debugging
  • Error callbacks for custom handling

Accessibility

The Video component is built with accessibility in mind:

  • Touch targets meet minimum size requirements
  • Clear visual feedback for interactions
  • Subtitle support for hearing accessibility
  • Proper semantic structure for screen readers

Performance Considerations

  • Efficient playback status updates (100ms intervals)
  • Optimized gesture handling
  • Memory cleanup on component unmount
  • Smooth animations with native driver when possible