Skip to content

VideoPlayer

Full-featured video player component with keyboard shortcuts, Picture-in-Picture, mini player and more.

Live Demo

loading

Basic Usage

tsx
import { VideoPlayer } from '@peakchao/react-media'

<VideoPlayer
  src="https://example.com/video.mp4"
  poster="https://example.com/poster.jpg"
/>

Props

PropTypeDefaultDescription
srcstringrequiredVideo source URL
posterstring-Poster image URL
autoplaybooleanfalseAuto-play
loopbooleanfalseLoop playback
mutedbooleanfalseMuted
controlsbooleantrueShow controls
widthstring | number'100%'Player width
heightstring | number'auto'Player height
primaryColorstring'#6366f1'Theme color
darkModebooleanfalseDark mode
playbackRatesnumber[][0.5, 0.75, 1, 1.25, 1.5, 2]Playback rates
keyboardShortcutsbooleantrueEnable keyboard shortcuts
showPiPbooleantrueShow PiP button
showSpeedbooleantrueShow speed button
showFullscreenbooleantrueShow fullscreen button
touchGesturesbooleantrueEnable touch gestures
miniPlayerbooleanfalseEnable mini player

Events

PropTypeDescription
onPlay() => voidFired when playback starts
onPause() => voidFired when paused
onEnded() => voidFired when ended
onTimeUpdate(payload) => voidProgress update
onVolumeChange(payload) => voidVolume change
onError(error) => voidPlayback error

Ref Methods

tsx
import { useRef } from 'react'
import { VideoPlayer, VideoPlayerRef } from '@peakchao/react-media'

function App() {
  const playerRef = useRef<VideoPlayerRef>(null)

  return (
    <>
      <VideoPlayer ref={playerRef} src="video.mp4" />
      <button onClick={() => playerRef.current?.play()}>Play</button>
      <button onClick={() => playerRef.current?.pause()}>Pause</button>
      <button onClick={() => playerRef.current?.toggleFullscreen()}>Fullscreen</button>
    </>
  )
}

Keyboard Shortcuts

KeyAction
SpacePlay/Pause
/ Seek ±5 seconds
/ Volume ±10%
MMute/Unmute
FToggle Fullscreen

Released under the MIT License.