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.

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