2017-05-03 09:04:16 +09:00
|
|
|
import React from 'react';
|
2017-04-22 03:05:35 +09:00
|
|
|
import PropTypes from 'prop-types';
|
2017-03-05 06:17:10 +09:00
|
|
|
|
2017-06-24 02:36:54 +09:00
|
|
|
export default class ExtendedVideoPlayer extends React.PureComponent {
|
2017-03-05 06:17:10 +09:00
|
|
|
|
2017-05-12 21:44:10 +09:00
|
|
|
static propTypes = {
|
|
|
|
src: PropTypes.string.isRequired,
|
2017-09-28 22:31:31 +09:00
|
|
|
alt: PropTypes.string,
|
2017-07-14 05:18:18 +09:00
|
|
|
width: PropTypes.number,
|
|
|
|
height: PropTypes.number,
|
2017-05-12 21:44:10 +09:00
|
|
|
time: PropTypes.number,
|
|
|
|
controls: PropTypes.bool.isRequired,
|
2017-05-21 00:31:47 +09:00
|
|
|
muted: PropTypes.bool.isRequired,
|
2018-04-09 06:15:25 +09:00
|
|
|
onClick: PropTypes.func,
|
2017-05-12 21:44:10 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
handleLoadedData = () => {
|
2017-04-14 00:01:09 +09:00
|
|
|
if (this.props.time) {
|
|
|
|
this.video.currentTime = this.props.time;
|
|
|
|
}
|
2017-04-22 03:05:35 +09:00
|
|
|
}
|
2017-04-14 00:01:09 +09:00
|
|
|
|
|
|
|
componentDidMount () {
|
|
|
|
this.video.addEventListener('loadeddata', this.handleLoadedData);
|
2017-04-22 03:05:35 +09:00
|
|
|
}
|
2017-04-14 00:01:09 +09:00
|
|
|
|
|
|
|
componentWillUnmount () {
|
|
|
|
this.video.removeEventListener('loadeddata', this.handleLoadedData);
|
2017-04-22 03:05:35 +09:00
|
|
|
}
|
2017-04-14 00:01:09 +09:00
|
|
|
|
2017-05-12 21:44:10 +09:00
|
|
|
setRef = (c) => {
|
2017-04-14 00:01:09 +09:00
|
|
|
this.video = c;
|
2017-04-22 03:05:35 +09:00
|
|
|
}
|
2017-04-14 00:01:09 +09:00
|
|
|
|
2018-04-09 06:15:25 +09:00
|
|
|
handleClick = e => {
|
|
|
|
e.stopPropagation();
|
|
|
|
const handler = this.props.onClick;
|
|
|
|
if (handler) handler();
|
|
|
|
}
|
|
|
|
|
2017-03-05 06:17:10 +09:00
|
|
|
render () {
|
2017-09-28 22:31:31 +09:00
|
|
|
const { src, muted, controls, alt } = this.props;
|
|
|
|
|
2017-03-05 06:17:10 +09:00
|
|
|
return (
|
2017-07-18 02:05:29 +09:00
|
|
|
<div className='extended-video-player'>
|
2017-04-14 00:01:09 +09:00
|
|
|
<video
|
|
|
|
ref={this.setRef}
|
2017-09-28 22:31:31 +09:00
|
|
|
src={src}
|
2017-04-14 00:01:09 +09:00
|
|
|
autoPlay
|
2017-09-28 22:31:31 +09:00
|
|
|
role='button'
|
|
|
|
tabIndex='0'
|
|
|
|
aria-label={alt}
|
|
|
|
muted={muted}
|
|
|
|
controls={controls}
|
|
|
|
loop={!controls}
|
2018-04-09 06:15:25 +09:00
|
|
|
onClick={this.handleClick}
|
2017-04-14 00:01:09 +09:00
|
|
|
/>
|
2017-03-05 06:17:10 +09:00
|
|
|
</div>
|
|
|
|
);
|
2017-04-22 03:05:35 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|