2018-11-08 18:08:07 +01:00
|
|
|
import React, { Component } from 'react'; // eslint-disable-line no-unused-vars
|
|
|
|
|
import YouTube from 'react-youtube'; // eslint-disable-line no-unused-vars
|
2018-11-24 01:41:45 +01:00
|
|
|
import { stringify } from 'querystring';
|
2018-11-08 18:08:07 +01:00
|
|
|
/* eslint no-console: ["error", { allow: ["info", "error"] }] */
|
|
|
|
|
|
|
|
|
|
class VideoPlayer extends Component {
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = {
|
|
|
|
|
opt: {
|
|
|
|
|
// height: '390',
|
|
|
|
|
// width: '640',
|
|
|
|
|
playerVars: {
|
|
|
|
|
// https://developers.google.com/youtube/player_parameters
|
|
|
|
|
autoplay: 0,
|
|
|
|
|
modestbranding: 1
|
|
|
|
|
}
|
2018-11-24 01:41:45 +01:00
|
|
|
},
|
|
|
|
|
videoId: '0J2QdDbelmY'
|
2018-11-08 18:08:07 +01:00
|
|
|
};
|
|
|
|
|
}
|
2018-11-24 01:41:45 +01:00
|
|
|
componentWillUpdate(nextProps, nextState){
|
|
|
|
|
if(nextProps.match.params.id === this.props.match.params.id){}
|
|
|
|
|
else{
|
|
|
|
|
this.setState((state, props) => { return { videoId: props.match.params.id }});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-25 19:45:16 +01:00
|
|
|
componentWillMount(){
|
2018-11-24 01:41:45 +01:00
|
|
|
if(this.props.match.params.id)
|
|
|
|
|
this.setState((state, props) => { return { videoId: props.match.params.id }});
|
|
|
|
|
|
|
|
|
|
}
|
2018-11-08 18:08:07 +01:00
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
return (
|
|
|
|
|
<React.Fragment>
|
|
|
|
|
<YouTube
|
|
|
|
|
opts={this.state.opt}
|
2018-11-24 01:41:45 +01:00
|
|
|
// this.props.match.params.id
|
|
|
|
|
videoId={this.state.videoId}
|
2018-11-08 18:08:07 +01:00
|
|
|
onReady={this._onReady}
|
|
|
|
|
onPlay={this._onPlay}
|
|
|
|
|
onError={this._onError}
|
2018-11-24 01:41:45 +01:00
|
|
|
onStateChange={this._onStateChange}
|
2018-11-08 18:08:07 +01:00
|
|
|
className="embed-responsive-item"
|
|
|
|
|
containerClassName="embed-responsive embed-responsive-16by9"
|
|
|
|
|
/>
|
|
|
|
|
</React.Fragment>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
_onError(event) {
|
|
|
|
|
console.error('on error', event);
|
|
|
|
|
// console.error(event);
|
|
|
|
|
}
|
|
|
|
|
_onPlay(event) {
|
2018-11-24 01:41:45 +01:00
|
|
|
// console.info('on play',event.target.getCurrentTime(), event);
|
|
|
|
|
// console.info(event.target.getApiInterface());
|
2018-11-08 18:08:07 +01:00
|
|
|
// console.warn(event.target.getDuration());
|
2018-11-24 01:41:45 +01:00
|
|
|
// console.info('go');
|
|
|
|
|
// while(event.target.getCurrentTime() < 15){}
|
|
|
|
|
// console.info(event.target.getCurrentTime());
|
2018-11-08 18:08:07 +01:00
|
|
|
}
|
|
|
|
|
_onReady(event) {
|
|
|
|
|
// access to player in all event handlers via event.target
|
2018-11-24 01:41:45 +01:00
|
|
|
// event.target.pauseVideo();
|
|
|
|
|
// console.info('on ready', event);
|
2018-11-08 18:08:07 +01:00
|
|
|
// console.warn(event);
|
|
|
|
|
// console.warn(event.target.getDuration());
|
|
|
|
|
}
|
2018-11-24 01:41:45 +01:00
|
|
|
_onStateChange(event) {
|
2018-11-25 19:45:16 +01:00
|
|
|
// console.info('statechange: ', event.data)
|
2018-11-24 01:41:45 +01:00
|
|
|
}
|
2018-11-08 18:08:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default VideoPlayer;
|