const messages = defineMessages({
toggle_sound: { id: 'video_player.toggle_sound', defaultMessage: 'Toggle sound' },
toggle_visible: { id: 'video_player.toggle_visible', defaultMessage: 'Toggle visibility' },
- expand_video: { id: 'video_player.expand', defaultMessage: 'Expand video' }
+ expand_video: { id: 'video_player.expand', defaultMessage: 'Expand video' },
+ expand_video: { id: 'video_player.video_error', defaultMessage: 'Video could not be played' }
});
const videoStyle = {
zIndex: '5'
};
-const spoilerStyle = {
+const coverStyle = {
marginTop: '8px',
textAlign: 'center',
height: '100%',
visible: !this.props.sensitive,
preview: true,
muted: true,
- hasAudio: true
+ hasAudio: true,
+ videoError: false
};
},
}
},
+ handleVideoError () {
+ this.setState({ videoError: true });
+ },
+
componentDidMount () {
if (!this.video) {
return;
}
this.video.addEventListener('loadeddata', this.handleLoadedData);
+ this.video.addEventListener('error', this.handleVideoError);
},
componentDidUpdate () {
}
this.video.addEventListener('loadeddata', this.handleLoadedData);
+ this.video.addEventListener('error', this.handleVideoError);
},
componentWillUnmount () {
}
this.video.removeEventListener('loadeddata', this.handleLoadedData);
+ this.video.removeEventListener('error', this.handleVideoError);
},
render () {
if (!this.state.visible) {
if (sensitive) {
return (
- <div role='button' tabIndex='0' style={{...spoilerStyle, width: `${width}px`, height: `${height}px` }} className='media-spoiler' onClick={this.handleVisibility}>
+ <div role='button' tabIndex='0' style={{...coverStyle, width: `${width}px`, height: `${height}px` }} className='media-spoiler' onClick={this.handleVisibility}>
{spoilerButton}
<span style={spoilerSpanStyle}><FormattedMessage id='status.sensitive_warning' defaultMessage='Sensitive content' /></span>
<span style={spoilerSubSpanStyle}><FormattedMessage id='status.sensitive_toggle' defaultMessage='Click to view' /></span>
);
} else {
return (
- <div role='button' tabIndex='0' style={{...spoilerStyle, width: `${width}px`, height: `${height}px` }} className='media-spoiler' onClick={this.handleVisibility}>
+ <div role='button' tabIndex='0' style={{...coverStyle, width: `${width}px`, height: `${height}px` }} className='media-spoiler' onClick={this.handleVisibility}>
{spoilerButton}
<span style={spoilerSpanStyle}><FormattedMessage id='status.media_hidden' defaultMessage='Media hidden' /></span>
<span style={spoilerSubSpanStyle}><FormattedMessage id='status.sensitive_toggle' defaultMessage='Click to view' /></span>
);
}
+ if (this.state.videoError) {
+ return (
+ <div style={{...coverStyle, width: `${width}px`, height: `${height}px` }} className='video-error-cover' >
+ <span style={spoilerSpanStyle}><FormattedMessage id='video_player.video_error' defaultMessage='Video could not be played' /></span>
+ </div>
+ );
+ }
+
return (
<div style={{ cursor: 'default', marginTop: '8px', overflow: 'hidden', width: `${width}px`, height: `${height}px`, boxSizing: 'border-box', background: '#000', position: 'relative' }}>
{spoilerButton}