Giter Club home page Giter Club logo

react-html5video's Introduction

react-html5video

A customizeable HTML5 Video that uses the familiar HTML5 video markup but with custom and configurable controls with i18n and a11y.

npm version npm downloads

View the demo.

Install

npm install react-html5video --save or bower install react-html5video --save

Include dist/ReactHtml5Video.css if you do not want to build your own CSS. Alternatively require src/assets/video.css if you want to compile the CSS yourself with css-loaders and url-loaders etc. See the demo Webpack config as an example.

Peer Dependencies

This component uses ES2015 and needs to be transpiled using something like babel-loader. You will also need to either polyfill or use babel-runtime. It depends on:

  • react@>=0.14.x
  • lodash.throttle@latest.

UMD

Alternatively if using the UMD module it is already transpiled to ES5 and lodash.throttle is included. You can find this build in the dist directory:

// Includes lodash.throttle and is transpiled already. No ES2015 polyfill is required.
var Video = require('react-html5video/dist/ReactHtml5Video');  
// Exports to this global
var Video = window.ReactHtml5Video.default;
// Requires es6 transpiling, an es6 polyfill/babel-runtime and all peer dependencies installed
import { default as Video, Controls, Play, Mute, Seek, Fullscreen, Time, Overlay } from 'react-html5video';

Usage

Simple Usage

Use normal HTML5 <video> markup with all the standard html attributes and supported React media events:

import Video from 'react-html5video';
render() {
    return (
        <Video controls autoPlay loop muted
            poster="http://sourceposter.jpg"
            onCanPlayThrough={() => {
                // Do stuff
            }}>
            <source src="http://sourcefile.webm" type="video/webm" />
        </Video>
    );
}

Advanced Usage

You can configure, customize and modify the controls by adding, removing and shuffling them as you desire. You can create your very own custom children components and controls that can interact with the video. All children components will receive these props. Obviously you can still call methods and set properties on the HTML5 DOM element directly if you have access to it with refs:

import { default as Video, Controls, Play, Mute, Seek, Fullscreen, Time, Overlay } from 'react-html5video';
render() {
    return (
        <Video controls autoPlay loop muted poster="http://sourceposter.jpg">
            <source src="http://sourcefile.mp4" type="video/mp4" />
            <source src="http://sourcefile.webm" type="video/webm" />
            <h1>Optional HTML and components can be added also</h1>
            <CustomComponent />

            /* As soon as a child is supplied that is not a `<source>`
            you have to define all controls and overlays as the default
            controls will have been removed. They are however exported
            and can be re-applied as below in any order. */
            <Overlay />
            <Controls>
                <Play />
                <Seek />
                <Time />
                <Mute />
                <Fullscreen />
                <CustomControlComponent />
            </Controls>
        </Video>
    );
}

i18n

There is some text used that could require translations. This can be done like so:

<Video copyKeys={{ key: value }}>

The default english copyKeys can be found in here.

a11y*

The custom controls provided are built using <button> and <input type="range"> which means basic keyboard controls are available when they are focused. For example, you can and hit the space bar on mute, play and fullscreen buttons as well as seek using the arrow keys when focused on the slider. All inputs have a visible focus outline and can be tabbed to. aria-label attributes for screen readers have been used where user interaction is required. Try tabbing through the demo with Vox enabled.

*Disclaimer: Unfortuantely I don't much experience with a11y but I have tried to use some of the features from PayPal's accessible HTML5 player. If anyone has further input on this please raise an issue or a pull request.

Props and Methods

All children components will receive the following properties via props:

  • copyKeys
  • duration
  • currentTime
  • buffered
  • paused
  • muted
  • volume
  • playbackRate
  • percentageBuffered
  • percentagePlayed

All children components receive the following methods via props:

  • play
  • pause
  • togglePlay
  • mute
  • unmute
  • toggleMute
  • seek
  • fullscreen
  • setVolume
  • setPlaybackRate

Contributing

Dev Setup

To run a server with hot module replacement:

    $ npm install
    $ cd demo
    $ npm install
    $ npm run dev-server

Open http://localhost:8082. You can now modify the files in both src and demo/src.

Issues

Feel free to raise and solve any existing issues as desired. Where possible please do try and replicate any bugs you may have using the react-html5video jsfiddle and include them in your ticket.

Thank You

BrowserStack for a free subscription to help test cross browser.

License

MIT

react-html5video's People

Contributors

mderrick avatar bernardofbbraga avatar ipanasenko avatar vedraan avatar jumasheff avatar kroko avatar

Watchers

 avatar James Cloos 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.