react-youtube 
Simple React component acting as a thin layer over the YouTube IFrame Player API
Features
Installation
$ npm install react-youtube
Usage
<YouTube
videoId={string}
id={string}
className={string}
containerClassName={string}
opts={obj}
onReady={func}
onPlay={func}
onPause={func}
onEnd={func}
onError={func}
onStateChange={func}
onPlaybackRateChange={func}
onPlaybackQualityChange={func}
/>
For convenience it is also possible to access the PlayerState constants through react-youtube:
YouTube.PlayerState
contains the values that are used by the YouTube IFrame Player API.
Example
import React from 'react';
import YouTube from 'react-youtube';
class Example extends React.Component {
render() {
const opts = {
height: '390',
width: '640',
playerVars: {
autoplay: 1
}
};
return (
<YouTube
videoId="2g811Eo7K8U"
opts={opts}
onReady={this._onReady}
/>
);
}
_onReady(event) {
event.target.pauseVideo();
}
}
Controlling the player
You can access & control the player in a way similar to the official api:
The API component will pass an event object as the sole argument to each of those functions the event handler props. The event object has the following properties:
- The event's
target
identifies the video player that corresponds to the event. - The event's
data
specifies a value relevant to the event. Note that the onReady
event does not specify a data
property.
License
MIT