Giter Site home page Giter Site logo

tranntuanduong / react-tuby Goto Github PK

View Code? Open in Web Editor NEW

This project forked from napthedev/react-tuby

0.0 1.0 0.0 1.44 MB

A React video player library with YouTube-like UI

Home Page: https://react-tuby.vercel.app

License: MIT License

TypeScript 82.21% HTML 0.68% SCSS 17.10%

react-tuby's Introduction

React Tuby

Build Size Version Downloads

A React video player library with YouTube-like UI

Demo

https://react-tuby.vercel.app

Feature

  • ๐Ÿ“น HTML Video, M3U8 support
  • ๐ŸŽ› Allow multiple qualities
  • ๐Ÿ“ฑ Fully responsive
  • ๐Ÿ–ฅ FullScreen cross browser support, even safari on iphone
  • ๐Ÿ“– Subtitles support
  • โฐ Speed control
  • โŒจ๏ธ Keyboard shortcuts
  • โš™๏ธ Support server side rendering (nextjs)
  • ๐Ÿ›  No extra dependencies
  • โœ… Auto fallback to default video if render fails on old browsers

Installation

npm i react-tuby
# or
# yarn add react-tuby

Import

import { Player } from "react-tuby";
import "react-tuby/css/main.css";

Example player

<Player
  src={[
    {
      quality: "Full HD",
      url:
        "https://cdn.glitch.me/cbf2cfb4-aa52-4a1f-a73c-461eef3d38e8/1080.mp4",
    },
    {
      quality: 720,
      url: "https://cdn.glitch.me/cbf2cfb4-aa52-4a1f-a73c-461eef3d38e8/720.mp4",
    },
    {
      quality: 480,
      url: "https://cdn.glitch.me/cbf2cfb4-aa52-4a1f-a73c-461eef3d38e8/480.mp4",
    },
  ]}
  subtitles={[
    {
      lang: "en",
      language: "English",
      url:
        "https://cdn.jsdelivr.net/gh/naptestdev/video-examples@master/en.vtt",
    },
    {
      lang: "fr",
      language: "French",
      url:
        "https://cdn.jsdelivr.net/gh/naptestdev/video-examples@master/fr.vtt",
    },
  ]}
  poster="https://cdn.jsdelivr.net/gh/naptestdev/video-examples@master/poster.png"
/>

Props

prop type description
src { quality: number | string; url: string; }[] | string; One url of video or array of qualities
subtitles { lang: string; language: string; url: string; }[] Array of subtitles, the first one will be default. Subtitle must be in .vtt format.
dimensions number | { width: number | string; height: number | string } Number: aspect ratio (height/width). Default: 56.25% (9/16) Width, height: set custom width and height
primaryColor string Customize the primary color. Default: #ff0000
poster string The url of poster image
seekDuration number Seek duration when pressing left/right key. Default: 10
playerKey string Unique user key to store video state in localStorage

Examples

Single src

<Player src="/your-video.mp4" />

Full width, height

<Player src="/your-video.mp4" dimensions={{ width: "100%", height: "100%" }} />

Custom props for video

This library uses render props to allow user to set custom render component

<Player src="/your-video.mp4">
  {(ref, props) => <video ref={ref} {...props} autoPlay loop />}
</Player>

Custom event

<Player src="/your-video.mp4">
  {(ref, { onPause, ...others }) => (
    <video
      ref={ref}
      {...others}
      onPause={e => {
        // The library original event
        onPause && onPause(e);

        // Do something here
        console.log("Paused");
      }}
    />
  )}
</Player>

Usage with m3u8 / HLS

Install react-hls-player

npm i react-hls-player --force

Usage

import ReactHlsPlayer from "react-hls-player";

<Player src="/your-video.m3u8">
  {(ref, props) => <ReactHlsPlayer playerRef={ref} {...props} />}
</Player>;

Issues

If you have some bug or have any feature request, feel free to submit an issue on the github repo.

react-tuby's People

Watchers

 avatar

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.