2017-05-03 02:04:16 +02:00
|
|
|
import React from 'react';
|
2017-04-21 20:05:35 +02:00
|
|
|
import PropTypes from 'prop-types';
|
2017-03-04 22:17:10 +01:00
|
|
|
|
2017-04-21 20:05:35 +02:00
|
|
|
class ExtendedVideoPlayer extends React.PureComponent {
|
2017-03-04 22:17:10 +01:00
|
|
|
|
2017-04-21 20:05:35 +02:00
|
|
|
constructor (props, context) {
|
|
|
|
super(props, context);
|
|
|
|
this.handleLoadedData = this.handleLoadedData.bind(this);
|
|
|
|
this.setRef = this.setRef.bind(this);
|
|
|
|
}
|
2017-03-04 22:17:10 +01:00
|
|
|
|
2017-04-13 17:01:09 +02:00
|
|
|
handleLoadedData () {
|
|
|
|
if (this.props.time) {
|
|
|
|
this.video.currentTime = this.props.time;
|
|
|
|
}
|
2017-04-21 20:05:35 +02:00
|
|
|
}
|
2017-04-13 17:01:09 +02:00
|
|
|
|
|
|
|
componentDidMount () {
|
|
|
|
this.video.addEventListener('loadeddata', this.handleLoadedData);
|
2017-04-21 20:05:35 +02:00
|
|
|
}
|
2017-04-13 17:01:09 +02:00
|
|
|
|
|
|
|
componentWillUnmount () {
|
|
|
|
this.video.removeEventListener('loadeddata', this.handleLoadedData);
|
2017-04-21 20:05:35 +02:00
|
|
|
}
|
2017-04-13 17:01:09 +02:00
|
|
|
|
|
|
|
setRef (c) {
|
|
|
|
this.video = c;
|
2017-04-21 20:05:35 +02:00
|
|
|
}
|
2017-04-13 17:01:09 +02:00
|
|
|
|
2017-03-04 22:17:10 +01:00
|
|
|
render () {
|
|
|
|
return (
|
2017-04-13 17:01:09 +02:00
|
|
|
<div className='extended-video-player'>
|
|
|
|
<video
|
|
|
|
ref={this.setRef}
|
|
|
|
src={this.props.src}
|
|
|
|
autoPlay
|
|
|
|
muted={this.props.muted}
|
|
|
|
controls={this.props.controls}
|
|
|
|
loop={!this.props.controls}
|
|
|
|
/>
|
2017-03-04 22:17:10 +01:00
|
|
|
</div>
|
|
|
|
);
|
2017-04-21 20:05:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2017-03-04 22:17:10 +01:00
|
|
|
|
2017-04-21 20:05:35 +02:00
|
|
|
ExtendedVideoPlayer.propTypes = {
|
|
|
|
src: PropTypes.string.isRequired,
|
|
|
|
time: PropTypes.number,
|
|
|
|
controls: PropTypes.bool.isRequired,
|
|
|
|
muted: PropTypes.bool.isRequired
|
|
|
|
};
|
2017-03-04 22:17:10 +01:00
|
|
|
|
|
|
|
export default ExtendedVideoPlayer;
|