ReactPlayer

3.4.0 · active · verified Sun Apr 19

ReactPlayer is a highly versatile React component designed for embedding and controlling various media sources directly within a web application. It supports a wide array of popular platforms, including YouTube, Vimeo, Wistia, TikTok, Spotify, and Twitch, as well as generic file paths, HLS, and DASH streams. The current stable version is 3.4.0. The library underwent a significant architectural rewrite in v3, transitioning to TypeScript and enhancing its modularity. Maintenance has been officially taken over by Mux, indicating a commitment to more frequent updates and fixes, ensuring its adaptability to evolving media platforms and web standards. Its key differentiators include broad support for numerous media providers and the ability to dynamically load players, which helps reduce initial bundle size when code splitting is enabled.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates a basic ReactPlayer setup with playback controls, volume adjustment, and mute functionality for a YouTube video.

import React, { useState } from 'react';
import ReactPlayer from 'react-player';

function MyVideoPlayer() {
  const [playing, setPlaying] = useState(false);
  const [volume, setVolume] = useState(0.8);
  const [muted, setMuted] = useState(false);

  return (
    <div style={{ width: '640px', height: '360px' }}>
      <h3>Now Playing: ReactPlayer Demo</h3>
      <ReactPlayer
        url='https://www.youtube.com/watch?v=LXb3EKWsInQ'
        playing={playing}
        controls={true}
        volume={volume}
        muted={muted}
        width='100%'
        height='100%'
        onPlay={() => setPlaying(true)}
        onPause={() => setPlaying(false)}
        onVolumeChange={val => setVolume(val)}
      />
      <div style={{ marginTop: '10px' }}>
        <button onClick={() => setPlaying(!playing)}>
          {playing ? 'Pause' : 'Play'}
        </button>
        <button onClick={() => setMuted(!muted)} style={{ marginLeft: '10px' }}>
          {muted ? 'Unmute' : 'Mute'}
        </button>
        <input
          type='range'
          min={0}
          max={1}
          step='any'
          value={volume}
          onChange={e => setVolume(parseFloat(e.target.value))}
          style={{ marginLeft: '10px', width: '100px' }}
        />
        <span>{(volume * 100).toFixed(0)}%</span>
      </div>
    </div>
  );
}

export default MyVideoPlayer;

view raw JSON →