You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.7 KiB

  1. import ImmutablePropTypes from 'react-immutable-proptypes';
  2. import PureRenderMixin from 'react-addons-pure-render-mixin';
  3. import IconButton from './icon_button';
  4. const videoStyle = {
  5. position: 'relative',
  6. zIndex: '1',
  7. width: '100%',
  8. height: '100%',
  9. objectFit: 'cover',
  10. top: '50%',
  11. transform: 'translateY(-50%)'
  12. };
  13. const muteStyle = {
  14. position: 'absolute',
  15. top: '10px',
  16. left: '10px',
  17. opacity: '0.8',
  18. zIndex: '5'
  19. };
  20. const VideoPlayer = React.createClass({
  21. propTypes: {
  22. media: ImmutablePropTypes.map.isRequired,
  23. width: React.PropTypes.number,
  24. height: React.PropTypes.number
  25. },
  26. getDefaultProps () {
  27. return {
  28. width: 196,
  29. height: 110
  30. };
  31. },
  32. getInitialState () {
  33. return {
  34. muted: true
  35. };
  36. },
  37. mixins: [PureRenderMixin],
  38. handleClick () {
  39. this.setState({ muted: !this.state.muted });
  40. },
  41. handleVideoClick (e) {
  42. e.stopPropagation();
  43. const node = ReactDOM.findDOMNode(this).querySelector('video');
  44. if (node.paused) {
  45. node.play();
  46. } else {
  47. node.pause();
  48. }
  49. },
  50. render () {
  51. return (
  52. <div style={{ cursor: 'default', marginTop: '8px', overflow: 'hidden', width: `${this.props.width}px`, height: `${this.props.height}px`, boxSizing: 'border-box', background: '#000', position: 'relative' }}>
  53. <div style={muteStyle}><IconButton title='Toggle sound' icon={this.state.muted ? 'volume-up' : 'volume-off'} onClick={this.handleClick} /></div>
  54. <video src={this.props.media.get('url')} autoPlay='true' loop={true} muted={this.state.muted} style={videoStyle} onClick={this.handleVideoClick} />
  55. </div>
  56. );
  57. }
  58. });
  59. export default VideoPlayer;