media: ImmutablePropTypes.map.isRequired,
width: React.PropTypes.number,
height: React.PropTypes.number,
- sensitive: React.PropTypes.bool
+ sensitive: React.PropTypes.bool,
+ intl: React.PropTypes.object.isRequired,
+ autoplay: React.PropTypes.bool
},
getDefaultProps () {
return {
- width: 196,
+ width: 239,
height: 110
};
},
return {
visible: !this.props.sensitive,
preview: true,
- muted: true
+ muted: true,
+ hasAudio: true
};
},
});
},
+ setRef (c) {
+ this.video = c;
+ },
+
+ handleLoadedData () {
+ if (('WebkitAppearance' in document.documentElement.style && this.video.audioTracks.length === 0) || this.video.mozHasAudio === false) {
+ this.setState({ hasAudio: false });
+ }
+ },
+
+ componentDidMount () {
+ if (!this.video) {
+ return;
+ }
+
+ this.video.addEventListener('loadeddata', this.handleLoadedData);
+ },
+
+ componentDidUpdate () {
+ if (!this.video) {
+ return;
+ }
+
+ this.video.addEventListener('loadeddata', this.handleLoadedData);
+ },
+
+ componentWillUnmount () {
+ if (!this.video) {
+ return;
+ }
+
+ this.video.removeEventListener('loadeddata', this.handleLoadedData);
+ },
+
render () {
- const { media, intl, width, height, sensitive } = this.props;
+ const { media, intl, width, height, sensitive, autoplay } = this.props;
let spoilerButton = (
<div style={spoilerButtonStyle} >
</div>
);
+ let muteButton = '';
+
+ if (this.state.hasAudio) {
+ muteButton = (
+ <div style={muteStyle}>
+ <IconButton title={intl.formatMessage(messages.toggle_sound)} icon={this.state.muted ? 'volume-off' : 'volume-up'} onClick={this.handleClick} />
+ </div>
+ );
+ }
+
if (!this.state.visible) {
if (sensitive) {
return (
}
}
- if (this.state.preview) {
+ if (this.state.preview && !autoplay) {
return (
<div style={{ cursor: 'pointer', position: 'relative', marginTop: '8px', width: `${width}px`, height: `${height}px`, background: `url(${media.get('preview_url')}) no-repeat center`, backgroundSize: 'cover' }} onClick={this.handleOpen}>
{spoilerButton}
return (
<div style={{ cursor: 'default', marginTop: '8px', overflow: 'hidden', width: `${width}px`, height: `${height}px`, boxSizing: 'border-box', background: '#000', position: 'relative' }}>
{spoilerButton}
- <div style={muteStyle}><IconButton title={intl.formatMessage(messages.toggle_sound)} icon={this.state.muted ? 'volume-off' : 'volume-up'} onClick={this.handleClick} /></div>
- <video src={media.get('url')} autoPlay='true' loop={true} muted={this.state.muted} style={videoStyle} onClick={this.handleVideoClick} />
+ {muteButton}
+ <video ref={this.setRef} src={media.get('url')} autoPlay='true' loop={true} muted={this.state.muted} style={videoStyle} onClick={this.handleVideoClick} />
</div>
);
}