React media container component to help build video & audio players.
npm install react-media-player --save
bower install react-media-player --save
import { Media, controls, utils } from 'react-media-player'
const { PlayPause, CurrentTime, Progress, SeekBar, Duration, MuteUnmute, Volume, Fullscreen } = controls
class MediaPlayer extends React.Component {
static contextTypes = {
playPause: PropTypes.func
}
render() {
const { Player } = this.props
const { isLoading, playPause, currentTime, duration } = this.context
return (
<div>
<div onClick={() => playPause()}>
{Player}
</div>
<nav className="media__controls">
<PlayPause />
<CurrentTime />
<Progress />
<SeekBar />
<Duration />
<MuteUnmute />
<Volume />
<Fullscreen />
</nav>
</div>
)
}
}
class App extends React.Component {
state = {
currSrc: 'http://www.youtube.com/embed/h3YVKTxTOgU'
}
render() {
return (
<Media src={this.state.currSrc}>
{Player => <MediaPlayer Player={Player} />}
</Media>
)
}
}
The source of the media you want to play. Currently supporting Youtube, Vimeo, and any HTML5 compatible video or audio.
Explicitly choose which component to render for the player. If not set, the library does its best to determine what player to render based on the source.
Passes in the Player
to be rendered.
This library makes heavy use of context, please be advised that with new releases of React the way context is handled in this library is subject to change.
clone repo
git clone git@github.com:souporserious/react-media-player.git
move into folder
cd ~/react-media-player
install dependencies
npm install
run dev mode
npm run dev
open your browser and visit: http://localhost:8080/