0.0.2 • Published 7 years ago

simple-react-player v0.0.2

Weekly downloads
6
License
CC0-1.0
Repository
github
Last release
7 years ago

SimpleReactPlayer

A react audio component for playing a variety of URLs, including file paths. This is a modified version of react player (http://cookpete.com/react-player) for a dj app i built. I stripped down react-player to a basic audio element that retains the props from the original react-player. I have also added a crossOrigin prop (works with SoundCloud SDK)

Polyfills

If you are using npm and need to support browsers without Promise you will need a Promise polyfill. To support Streamable or Vidme videos you will also need a fetch polyfill for browsers without fetch

Usage

npm install simple-react-player --save
import React, { Component } from 'react'
import ReactPlayer from 'react-player'

class App extends Component {
  render () {
    return <ReactPlayer url='https://www.youtube.com/watch?v=ysz5S6PUM-U' playing />
  }
}

Props

PropDescriptionDefault
urlThe url of a video or song to play
playingSet to true or false to pause or play the mediafalse
loopSet to true or false to loop the mediafalse
controlsSet to true or false to display native player controlsNote: Vimeo player controls are not configurable and will always displayfalse
volumeSets the volume of the appropriate player0.8
playbackRateSets the playback rate of the appropriate player1
widthSets the width of the player640
heightSets the height of the player360
hiddenSet to true to hide the playerfalse
classNamePass in a className to set on the root element
styleAdd inline styles to the root element
progressFrequencyThe time between onProgress callbacks, in milliseconds1000
crossOrigineither 'anonymous' or 'use-credentials'anonymous

Callback props

Callback props take a function that gets fired on various player events:

PropDescription
onReadyCalled when media is loaded and ready to play. If playing is set to true, media will play immediately
onStartCalled when media starts playing
onPlayCalled when media starts or resumes playing after pausing or buffering
onProgressCallback containing played and loaded progress as a fractioneg { played: 0.12, loaded: 0.34 }
onDurationCallback containing duration of the media, in seconds
onPauseCalled when media is paused
onBufferCalled when media starts buffering
onEndedCalled when media finishes playing
onErrorCalled when an error occurs whilst attempting to play media

Config props

This prop allows you to override the parameters for the player:

PropDescription
fileConfigConfiguration object for the file player.Set attributes to apply element attributes.

Methods

To seek to a certain part of the media, there is a seekTo(fraction) instance method that will seek to the appropriate place in the media. See App.js for an example of this using refs.

Supported media

Thanks