0.1.0 • Published 6 years ago

videoact v0.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

videoact is a highly configrable html5 video component built from the ground up using React library.

Usage

ES6

npm install videoact --save
# or
yarn add videoact
import React, { Component } from 'react';
import Videoact from 'videoact';

class App extends Component {
  render () {
    return <Videoact src='https://media.w3.org/2010/05/sintel/trailer_hd.mp4' />
  }
}

Es5

<script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js" type="text/javascript"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js" type="text/javascript"></script>
<script crossorigin src="https://unpkg.com/videoact@0.0.2/lib/index.js" type="text/javascript"></script>
<script type="text/javascript">
  var props = {
    src: 'https://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_30mb.mp4',
    autoplay: true,
    controls: true,
  };
  ReactDOM.render(
    React.createElement(videoact.default, props, null),
    document.getElementById('app')
  );
</script> 

Properties

Example
<Videoact
  autoplay={true}
  controls={true}
  src={'https://www.videos.com/video.mp4'}
/>
List
PropertyDescriptionDefault
autoplayset Set if the video should start playing as soon as it is loadedfalse
controlsset Set if the video should display controls (like play/pause etc.)true
crossOriginset the CORS settings of the video"anonymous"
currentTimeset the current playback position in the video (in seconds)0
defaultMutedset Set if the video should be muted by defaultfalse
defaultPlaybackRateset the default speed of the video playback1
downloadset the download optionfalse
heightset the video heightnull
loopset Set if the video should start over again when finishedfalse
mediaGroupset the group the video belongs to (used to link multiple video elements)"videoact"
mutedset Set if the video is muted or notfalse
playbackRateset the speed of the video playback1
preloadset Set if the video should be loaded when the page loadsfalse
ratioset the video aspect ratio3.166 (19/6)
srcset the current source of the video element""
volumeset the volume of the video1
widthset the video width"100%"

Note: If width and height was specified, the ratio be ignored also if you want to keep the original video aspect ratio set ratio it to null

Property list (get)

Example
<Videoact {...props} ref={e => {this.video = e}} />
<button onClick={()=> { alert(this.video.duration) }}>video duration</button>
List
PropertyDescription
audioTracksget an AudioTrackList object representing available audio tracks
autoplayget whether the video should start playing as soon as it is loaded
bufferedget a TimeRanges object representing the buffered parts of the video
controllerget the MediaController object representing the current media controller of the video
controlsget whether the video should display controls (like play/pause etc.)
crossOriginget the CORS settings of the video"anonymous"
currentSrcget the URL of the current video
currentTimeget the current playback position in the video (in seconds)
defaultMutedget whether the video should be muted by default
defaultPlaybackRateget the default speed of the video playback
durationget the length of the current video (in seconds)
endedget whether the playback of the video has ended or not
errorget a MediaError object representing the error state of the video
loopget whether the video should start over again when finished
mediaGroupget the group the video belongs to (used to link multiple video elements)
mutedget whether the video is muted or not
networkStateget the current network state of the video
pausedget whether the video is paused or not
playbackRateget the speed of the video playback
playedget a TimeRanges object representing the played parts of the video
preloadget whether the video should be loaded when the page loads
readyStateget the current ready state of the video
seekableget a TimeRanges object representing the seekable parts of the video
seekingget whether the user is currently seeking in the video
srcget the current source of the video element
startDateget a Date object representing the current time offset
textTracksget a TextTrackList object representing the available text tracks
videoTracksget a VideoTrackList object representing the available video tracks
volumeget the volume of the video

Events

The HTML5 DOM has events for the video elements, so all what I did here is mapping the native events to videoact component.

Example
<Videoact
  {...props}
  onEnded={() => { alert('finished') }}
  onPause={() => { alert('paused') }}
/>
List
EventDescription
onAbortWhen the loading of an video is aborted
onCanPlayWhen the browser can start playing the video
onCanPlayThroughWhen the browser can play through the video without stopping for buffering
onDurationChangeWhen the download button clicked
onDurationChangeWhen the duration of the video is changed
onEmptiedWhen the current playlist is empty
onEndedWhen the current playlist is ended
onErrorWhen an error occurred during the loading of an video
onLoadedDataWhen the browser has loaded the current frame of the video
onLoadedMetadataWhen the browser has loaded meta data for the video
onLoadStartWhen the browser starts looking for the video
onPauseWhen the video has been paused
onPlayWhen the video has been started or is no longer paused
onPlayingWhen the video is playing after having been paused or stopped for buffering
onProgressWhen the browser is downloading the video
onRateChangeWhen the playing speed of the video is changed
onSeekedWhen the user is finished moving/skipping to a new position in the video
onSeekingWhen the user starts moving/skipping to a new position in the video
onStalledWhen the browser is trying to get media data, but data is not available
onSuspendWhen the browser is intentionally not getting media data
onTimeUpdateWhen the current playback position has changed
onVolumeChangeWhen the volume has been changed
onWaitingWhen the video stops because it needs to buffer the next frame

Methods

These are all the HTML5 video methods that allow you to manipulate the videoact component.

Example

<Videoact {...props} ref={e => {this.video = e}} />
<button onClick={()=> { this.video.play() }} >play</button>

Method list

MethodDescription
addTextTrackAdds a new text track to the video
canPlayTypeChecks if the browser can play the specified video type
loadRe-loads the video element
playStarts playing the video
pausePauses the currently playing video
fullscreen*Request full screen if supported
exitFullscreen*Request exit from full screen

Note: Fullscreen need to be called from within an event handler or otherwise they will be denied.

Methods

  • add volume control
  • add seeker