diff --git a/src/renderer/component/video/view.jsx b/src/renderer/component/video/view.jsx index b664ee88f..c1663c5e3 100644 --- a/src/renderer/component/video/view.jsx +++ b/src/renderer/component/video/view.jsx @@ -19,6 +19,7 @@ type Props = { nsfw: boolean, thumbnail: string, }, + autoplay: boolean, isLoading: boolean, isDownloading: boolean, playingUri: ?string, @@ -34,56 +35,38 @@ type Props = { mediaPosition: ?number, className: ?string, obscureNsfw: boolean, - play: string => void + play: string => void, }; class Video extends React.PureComponent { - componentWillUnmount() { - this.props.cancelPlay(); - } - componentDidMount() { this.handleAutoplay(this.props); } componentWillReceiveProps(nextProps: Props) { - this.handleAutoplay(nextProps); + if ( + this.props.autoplay !== nextProps.autoplay || + this.props.fileInfo !== nextProps.fileInfo || + this.props.isDownloading !== nextProps.isDownloading || + this.props.playingUri !== nextProps.playingUri + ) { + this.handleAutoplay(nextProps); + } + } + + componentWillUnmount() { + this.props.cancelPlay(); } handleAutoplay(props: Props) { - const { - autoplay, - obscureNsfw, - playingUri, - fileInfo, - costInfo, - isDownloading, - uri, - load, - play - } = props; + const { autoplay, playingUri, fileInfo, costInfo, isDownloading, uri, load, play, metadata } = props; - const playable = ( - autoplay && - obscureNsfw === false && - playingUri !== uri - ); + const playable = autoplay && playingUri !== uri && metadata && !metadata.nsfw; - if ( - playable && - costInfo && - costInfo.cost === 0 && - !fileInfo && - !isDownloading - ) { + if (playable && costInfo && costInfo.cost === 0 && !fileInfo && !isDownloading) { load(uri); play(uri); - } - else if ( - playable && - fileInfo && - fileInfo.blobs_completed > 0 - ) { + } else if (playable && fileInfo && fileInfo.blobs_completed > 0) { play(uri); } } @@ -137,7 +120,8 @@ class Video extends React.PureComponent { const poster = metadata && metadata.thumbnail; const layoverClass = classnames('content__cover', { 'card__media--nsfw': shouldObscureNsfw }); - const layoverStyle = !shouldObscureNsfw && poster ? { backgroundImage: `url("${poster}")` } : {}; + const layoverStyle = + !shouldObscureNsfw && poster ? { backgroundImage: `url("${poster}")` } : {}; return (
@@ -147,7 +131,7 @@ class Video extends React.PureComponent {
- ) : ( + ) : (