Code Monkey home page Code Monkey logo

react-all-player's Introduction

react-all-player

react-all-player is a simple, lightweight, accessible and customizable React media player that supports modern browsers.

Checkout the demo

npm version

Screenshot of react-all-player

Features

  • ๐Ÿ“ผ HTML Video & Audio, YouTube & Vimeo - support for the major formats
  • ๐Ÿ’ช Accessible - full support for VTT captions and screen readers
  • ๐Ÿ”ง Customizable - make the player look how you want with the markup you want
  • ๐Ÿ“ฑ Responsive - works with any screen size
  • ๐Ÿ“น Streaming - support for hls.js, and dash.js streaming playback
  • ๐ŸŽ› API - toggle playback, volume, seeking, and more through a standardized API
  • ๐ŸŽค Events - no messing around with Vimeo and YouTube APIs, all events are standardized across formats
  • ๐Ÿ”Ž Fullscreen - supports native fullscreen with fallback to "full window" modes
  • โŒจ๏ธ **Shortcuts - supports keyboard shortcuts
  • ๐Ÿ–ฅ Picture-in-Picture - supports picture-in-picture mode
  • ๐Ÿ“ฑ Playsinline - supports the playsinline attribute
  • ๐ŸŽ Speed controls - adjust speed on the fly
  • ๐Ÿ“– Multiple captions - support for multiple caption tracks
  • ๐Ÿ‘Œ Preview thumbnails - support for displaying preview thumbnails

Usage

npm install react-all-player # or yarn add react-all-player
import ReactAllPlayer from 'react-all-player';

<ReactAllPlayer
  sources={[
    {
      file: 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-1080p.mp4',
      label: '1080p',
    },
    {
      file: 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-720p.mp4',
      label: '720p',
    },
  ]}
  subtitles={[
    {
      lang: 'en',
      language: 'English',
      file: 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.en.vtt',
    },
    {
      lang: 'fr',
      language: 'French',
      file: 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.fr.vtt',
    },
  ]}
/>;

For NextJS

Dynamically import ReactAllPlayer to ensure it's only loaded on the client-side

import dynamic from "next/dynamic";
const ReactAllPlayer = dynamic(() => import('react-all-player'), {
  ssr: false,
});

Props

react-all-player accepts video element props and these specific props

Prop Type Description Default Required
sources Source[] An array of sources contain file, label and type null true
subtitles Subtitle[] An array of subtitles contain file, lang and language null false
hlsRef React.MutableRefObject<Hls | null> hls.js instance ref React.createRef() false
dashRef React.MutableRefObject<DashJS.MediaPlayerClass | null> dashjs instance ref React.createRef() false
hlsConfig Hls['config'] hls.js config {} false
changeSourceUrl (currentSourceUrl: string, source: Source): string A function that modify given source url (hls only) () => null false
onHlsInit (hls: Hls): void A function that called after hls.js initialization () => null false
onDashInit (dash: DashJS.MediaPlayerClass): void A function that called after dashjs initialization () => null false
onInit (videoEl: HTMLVideoElement): void A function that called after video initialization () => null false
ref React.MutableRefObject<HTMLVideoElement | null> video element ref null false
i18n I18n Translations Default Translations false
hotkeys Hotkey[] Hotkeys (shortcuts) Default Hotkeys false
components Component[] See Customization Default components false
thumbnail string Thumbnails on progress bar hover null false

Customization

You can customize the player by passing defined components with components props. See defined components

By passing components, the passed components will override default existing components. Allow you to customize the player how you want it to be.

Example

import ReactAllPlayer, { TimeIndicator } from 'react-all-player';

<ReactAllPlayer
  {...props}
  components={{
    Controls: () => {
      return (
        <div className="flex items-center justify-between">
          <p>A custom Controls component</p>

          <TimeIndicator />
        </div>
      );
    },
  }}
/>;

Note: use built-in hooks and components for better customization

Override structure

react-all-player use this default structure

To override it, simply pass your own structure as react-all-player's children

import ReactAllPlayer, { Controls, Player, Overlay } from 'react-all-player';

<ReactAllPlayer {...props}>
  <div>
    <div>
      <Player />
    </div>
    <div>
      <Controls />
    </div>
    <div>
      <Overlay />
    </div>
    <div>
      <p>here!</p>
    </div>
  </div>
</ReactAllPlayer>;

Methods

You can access to the video element by passing ref to react-all-player and use all its methods.

Supported formats

react-all-player supports all video element supported formats and HLS format

Contributing

See the contribution guidelines before creating a pull request.

react-all-player's People

Contributors

asadbek064 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

animettv

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.