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.

75 lines
1.8 KiB

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