web: common: MediaViewer. stop playing invisible video/audio

This commit is contained in:
NikolayRechkin 2020-04-30 11:37:16 +03:00
parent 62fee1ecfe
commit f8218bf17f
2 changed files with 29 additions and 17 deletions

View File

@ -212,7 +212,7 @@ class MediaViewer extends React.Component {
]}
/>
:
<StyledVideoViewer url={url} isVideo={isVideo} />
<StyledVideoViewer url={url} playing ={this.state.visible} isVideo={isVideo} />
)
}
<div className="mediaViewerToolbox"></div>

View File

@ -181,7 +181,7 @@ class VideoViewer extends Component {
state = {
url: this.props.url,
pip: false,
playing: true,
playing: this.props.playing,
controls: false,
light: false,
volume: 0.3,
@ -201,14 +201,25 @@ class VideoViewer extends Component {
pip: false
})
}
componentDidUpdate(prevProps) {
componentDidUpdate(prevProps, prevState) {
let newUrl = prevState.url;
let newPlaying = prevState.playing;
if (this.props.url !== prevProps.url || this.props.playing !== prevProps.playing) {
if (this.props.url !== prevProps.url) {
newUrl = this.props.url
}
if (this.props.playing !== prevProps.playing) {
newPlaying = this.props.playing
}
this.setState(
{
url: this.props.url
url: newUrl,
playing: newPlaying
}
);
}
}
handlePlayPause = () => {
this.setState({ playing: !this.state.playing })
@ -443,7 +454,8 @@ class VideoViewer extends Component {
VideoViewer.propTypes = {
isVideo: PropTypes.bool,
url: PropTypes.string
url: PropTypes.string,
playing: PropTypes.bool
}
export default VideoViewer;