1.8.1 • Published 5 years ago

react-drive-in2 v1.8.1

Weekly downloads
114
License
-
Repository
github
Last release
5 years ago

React Drive-In

npm release

A wicked awesome replacement for BigVideo.js that is lighter with fewer dependencies. It does not use jQuery, video.js, or any other large libraries. Only 5k minified and gzipped. This React component is a wrapper over the core Drive-In lib.

Demo and some example functionality here: github.io

Created by Ronik Design.

Install

So easy. React is the only required peer dependency: React.

  • Using NPM
  $ npm install --save-dev react-drive-in

Usage

  • The easiest example
  const React = require("react");
  const ReactDOM = require("react-dom");
  const ReactDriveIn = require("react-drive-in");

  ReactDOM.render(
    <ReactDriveIn
      show="http://raw.githubusercontent.com/ronik-design/react-drive-in/master/example/glacier.mp4"
      poster="http://raw.githubusercontent.com/ronik-design/react-drive-in/master/example/glacier.jpg"
    />,
    $mountNode
  );
  • More complex
  const React = require("react");
  const ReactDOM = require("react-dom");
  const ReactDriveIn = require("react-drive-in");

  const PLAYLIST = [
    [
      "https://github.com/ronik-design/react-drive-in/blob/master/example/pelo.mp4?raw=true",
      "https://github.com/ronik-design/react-drive-in/blob/master/example/pelo.ogv?raw=true",
      "https://github.com/ronik-design/react-drive-in/blob/master/example/pelo.jpg?raw=true"
    ],
    [
      "https://github.com/ronik-design/react-drive-in/blob/master/example/kaledo.mp4?raw=true",
      "https://github.com/ronik-design/react-drive-in/blob/master/example/kaledo.ogv?raw=true",
      "https://github.com/ronik-design/react-drive-in/blob/master/example/kaledo.jpg?raw=true"
    ],
    [
      "http://raw.githubusercontent.com/ronik-design/react-drive-in/master/example/glacier.mp4",
      "http://raw.githubusercontent.com/ronik-design/react-drive-in/master/example/glacier.ogv",
      "http://raw.githubusercontent.com/ronik-design/react-drive-in/master/example/glacier.jpg"
    ]
  ];

  const onPlaying = function(itemNum) {};
  const onPause = function() {};

  ReactDOM.render(
    <ReactDriveIn
      showPlaylist={playlist}
      onPlaying={onPlaying}
      onPause={onPause}
      loop
      mute
    />,
    $mountNode
  );
  • Sample bundling script for the browser using rollup.js:
import babel from "rollup-plugin-babel";
import npm from "rollup-plugin-npm";
import commonjs from "rollup-plugin-commonjs";
import replace from "rollup-plugin-replace";

export default {
  entry: "lib/main.jsx",
  plugins: [
    replace({ "process.env.NODE_ENV": JSON.stringify("production") }),
    npm({ jsnext: true, main: true }),
    commonjs(),
    babel()
  ],
  dest: "dist/bundle.js",
  moduleName: "MyBundle",
  format: "iife"
};

What to show

The show and showPlaylist properties have many options. See example/index.html for an fairly complex set up.

Details

The HTML structure of this element looks like:

  <div id="drive-in-wrap">
    <div class="drive-in-media">
      <video> OR <img>
    </div>
  </div>

The included CSS sets up some required styles for it to function correctly.

The component falls back to using an image on touch devices, since many will not play video inline. Thus, you might want to specify fallback images either through the poster property or in the fallback arrays.

Formats

The component currently understands and supports, mp4, ogv, webm, jpg, gif, png.

Component API

<Video> component:

PropertyTypeDefaultRequiredDescription
showString,ArraynonenoThe video or video fallback array to show.
showPlaylistArraynonenoAn array of video URL strings, or of video fallback arrays.
playNumbernonenoSimilar to show but used to play a video at a given index in the showPlaylist array.
pausedBooleanfalsenoSet the playlist to a paused state on initial load.
posterStringnonenoA fallback image to use, when all else fails.
muteBooleantruenoShould the videos be played muted?
loopBooleantruenoShould videos / playlists loop or begin again when finished?
loopPlaylistItemsBooleanfalsenoIndividual playlist videos will loop, rather than the whole list itself.
slideshowBooleanfalsenoForce the component to display fallback images / poster rather than videos.
onPlayingFunctionnullnoRegister a callback for when the video / slideshow starts playing.
onPauseFunctionnullnoRegister a callback for when the video / slideshow is paused.
onTimeFunctionnullnoEmits regular time-tracking events from Drive-In lib with current media item play position.
onTimeFrequencyNumber500noFrequency at which to emit time-tracking events.
onCanPlayFunctionnullnoCallback for when a loaded media item can play.
playbackRateNumber1.0noAdjust the playback rate of videos. Per the HTML5 video method.
isTouchFunctionnullnoProvide a custom function for touch detection

Developing

You can clone this repo and then:

$ npm install
$ npm run develop

This will install all dev dependencies, let you watch sources and run a dev server.

License

See the License file.

Credit