-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(guides): Add a basic ReactJS guide and update the FAQ (#3972)
- Loading branch information
1 parent
7b0d738
commit 05b39fe
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -367,6 +367,8 @@ Coming soon... | |
|
||
### React | ||
|
||
See [ReactJS integration example](./react.md) | ||
|
||
### Ember | ||
|
||
### Angular |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# video.js and ReactJS integration | ||
|
||
Here's a basic ReactJS player implementation. | ||
|
||
It just instantiates the video.js player on `componentDidMount` and destroys it on `componentWillUnmount`. | ||
|
||
```jsx | ||
import React from 'react'; | ||
import videojs from 'video.js' | ||
|
||
export default class VideoPlayer extends React.Component { | ||
componentDidMount() { | ||
// instantiate video.js | ||
this.player = videojs(this.videoNode, this.props, function onPlayerReady() { | ||
console.log('onPlayerReady', this) | ||
}); | ||
} | ||
|
||
// destroy player on unmount | ||
componentWillUnmount() { | ||
if (this.player) { | ||
this.player.dispose() | ||
} | ||
} | ||
|
||
// wrap the player in a div with a `data-vjs-player` attribute | ||
// so videojs won't create additional wrapper in the DOM | ||
// see https://github.com/videojs/video.js/pull/3856 | ||
render() { | ||
return ( | ||
<div data-vjs-player> | ||
<video ref={ node => this.videoNode = node } className="video-js"></video> | ||
</div> | ||
) | ||
} | ||
} | ||
``` | ||
|
||
You can then use it like this: | ||
|
||
```jsx | ||
// see https://github.com/videojs/video.js/blob/master/docs/guides/options.md | ||
const videoJsOptions = { | ||
autoPlay: true, | ||
controls: true, | ||
sources: [{ | ||
src: '/path/to/video.mp4', | ||
type: 'video/mp4' | ||
}] | ||
} | ||
|
||
return <VideoPlayer { ...videoJsOptions } /> | ||
``` | ||
|
||
Dont forget to include the video.js CSS, located at `video.js/dist/video-js.css`. |