Command palette

@yasinsensoy/native

React Native · Components

VideoPlayer

Video player (same API as the web VideoPlayer).

11 exports

Live example

The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.

Preview

0:00 / 0:00

Code

import { VideoPlayer } from "@yasinsensoy/native";

<VideoPlayer
  src="/videos/intro.mp4"
  poster="/videos/intro.jpg"
  title="Intro"
  tracks={[{ src: "/videos/tr.vtt", srcLang: "tr", label: "Turkish", default: true }]}
/>

Events

  1. Events appear here when you interact with the preview.

Reels style: muted, looping, pauses on tap

Import

import {
  VideoFrameImage,
  VideoPlayer,
  cachedVideoFrame,
  extractVideoFrame,
  useVideoFrame,
} from "@yasinsensoy/native";

VideoPlayer

component

Video player (same API as the web VideoPlayer). The picture is drawn by the library's own native view (Android MediaPlayer, iOS AVPlayer; no extra library); the controls are drawn the same on both platforms.

  • Controls: play/pause, seek bar (draggable), duration, captions, speed and quality menus, mute, fullscreen. They hide a few seconds after playback starts; a tap shows them.
  • Double tap: the right half skips forward, the left half back.
  • `controls="minimal"`: Reels/Shorts style; tap to pause/play.
  • Cover: without poster a frame is extracted from the video.
  • Fullscreen: covers the whole screen above the app; the Android back button exits.
  • Pauses when the app goes to the background.

Importing @yasinsensoy/native/video-player adds the video native module to the build.

VideoPlayer({ src, poster, autoPoster, title, tracks, autoPlay, muted: mutedProp, loop, controls, aspectRatio, fit, playbackRates, seekStep, startTime, rememberVolume, headers, label, onPlay, onPause, onEnded, onTimeUpdate, onError, onFullscreenChange, style, ref, testID, }: VideoPlayerProps): JSX.Element

Examples

<VideoPlayer src="https://…/intro.mp4" poster="https://…/cover.jpg" title="Intro" />

// Reels style, automatic and muted
<VideoPlayer src={clip} controls="minimal" autoPlay muted loop aspectRatio={9 / 16} fit="cover" />

Shows a frame of a video without a cover image as an image (fills the container). Empty until the frame is extracted; fades in when it is.

VideoFrameImage({ src, fit, onFrame, style }: VideoFrameImageProps): JSX.Element | null

Examples

<View style={{ aspectRatio: 16 / 9 }}>
  <VideoFrameImage src="https://…/clip.mp4" />
</View>

The extracted frame if cached; otherwise undefined.

cachedVideoFrame(src: string): VideoFrame | undefined

Extracts a frame of the video (see the top of the file). A single job runs per address; the result is cached. When signal is aborted and nobody else is waiting, the job leaves the queue. null if the video cannot be opened or the video module is not in the build.

extractVideoFrame(src: string, { signal }?: { signal?: AbortSignal; }): Promise<VideoFrame | null>

Examples

const frame = await extractVideoFrame("https://…/clip.mp4");
if (frame) setCover(frame.url);

Frame of a video without a cover image. No job starts while enabled is false; the pending job is cancelled when the component unmounts (or the address changes).

useVideoFrame(src: string | undefined, { enabled }?: { enabled?: boolean; }): VideoFrame | undefined

VideoFrame

interface

Result of extractVideoFrame.

NameTypeDescription
urlstringImage URL of the frame (file://).
widthnumberWidth of the frame (px). The ratio is the video's ratio.
heightnumberHeight of the frame (px).

VideoFrameImage props.

NameTypeDefaultDescription
srcstringVideo address.
fit?"cover" | "contain""cover"Fit in the box.
onFrame?(frame: VideoFrame) => voidWhen the frame is extracted (to measure its ratio).
style?StyleProp<ImageStyle>Image style. Fills the container if omitted.

VideoSource

interface

A video source for VideoPlayer.

NameTypeDescription
srcstringVideo address.
type?stringMIME type (for source lists shared with web; not used on native).
label?stringQuality name ("1080p", "720p"). If any source is named, a quality menu appears in the settings; switching keeps the position and playback state. The first source is the default.

VideoTrack

interface

Caption file (WebVTT) for VideoPlayer.

NameTypeDefaultDescription
srcstringURL of the .vtt file.
srcLangstringLanguage code ("tr", "en").
labelstringName shown in the menu ("English").
kind?"subtitles" | "captions""subtitles"Kind.
default?booleanInitially on.

For controlling the player from code (ref).

NameTypeDescription
play(): voidPlays.
pause(): voidStops.
toggle(): voidPlays or pauses.
seek(time: number): voidSeeks to a position (seconds).
currentTimenumberCurrent position (seconds).
durationnumberDuration (seconds; 0 if unknown).
enterFullscreen(): voidEnters fullscreen.
exitFullscreen(): voidExits fullscreen.

VideoPlayer props.

NameTypeDefaultDescription
srcstring | readonly VideoSource[]Video URL or a source list. See VideoSource.
poster?stringCover image shown before the video starts.
autoPoster?booleantrueIf poster is omitted, a frame is extracted from the video as the cover (on the native side, cached).
title?stringTitle. Shown at the top in fullscreen.
tracks?readonly VideoTrack[]Captions (WebVTT). See VideoTrack.
autoPlay?booleanPlay automatically when opened.
muted?booleanStarts muted.
loop?booleanStarts over when finished.
controls?boolean | "minimal"trueControls: true the full bar; "minimal" Reels/Shorts style (tap to pause/play, a thin seek bar and a mute button at the bottom); false none.
aspectRatio?number | "auto" | "fill"16 / 9Aspect ratio. A number (16 / 9), "auto" (the video's own ratio) or "fill" (fills the container; you give the size).
fit?"contain" | "cover""contain"How the picture fits the box.
playbackRates?readonly number[][0.5, 0.75, 1, 1.25, 1.5, 2]Speeds in the settings.
seekStep?number5Seconds skipped on double tap (twice that is skipped).
startTime?numberStart position (seconds).
rememberVolume?booleantrueRemember the mute preference while the app stays open; players opened later start with the last choice. On phones volume is on the hardware buttons; there is no volume bar.
headers?Record<string, string>Request headers (Authorization for protected videos).
label?stringtitleScreen reader name.
onPlay?() => voidWhen playback starts.
onPause?() => voidOn pause.
onEnded?() => voidOn end.
onTimeUpdate?(time: number, duration: number) => voidWhen the position changes (several times a second), with the current position and duration.
onError?() => voidWhen the video cannot be opened.
onFullscreenChange?(fullscreen: boolean) => voidWhen entering and exiting fullscreen.
style?StyleProp<ViewStyle>Style of the box.
ref?Ref<VideoPlayerHandle>For controlling the player from code. See VideoPlayerHandle.
testID?stringTest id.