Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: [UEPR-118] Player sound playback #8980

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/components/intro/intro.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const connect = require('react-redux').connect;
const PropTypes = require('prop-types');
const React = require('react');

const classnames = require('classnames');

const navigationActions = require('../../redux/navigation.js');

const Video = require('../video/video.jsx');
Expand Down Expand Up @@ -52,13 +54,8 @@ class Intro extends React.Component {

</FlexRow>
<FlexRow className="intro-video-container">
{this.state.videoOpen ?
{!this.state.videoOpen &&
(
<Video
className="intro-video"
videoId="joal01i8b1"
/>
) : (
<div
className="video-image"
onClick={this.handleShowVideo}
Expand All @@ -75,6 +72,12 @@ class Intro extends React.Component {
</div>
)
}

<Video
className={classnames('intro-videos')}
videoId="joal01i8b1"
shouldPlay={this.state.videoOpen}
/>
</FlexRow>
</FlexRow>

Expand Down
22 changes: 18 additions & 4 deletions src/components/video/video.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ class Video extends React.Component {
videoStarted: false
};
}

componentDidMount () {
if (!this.props.shouldPlay) {
return;
}

/**
uses code snippets from
https://github.com/mrdavidjcole/wistia-player-react/blob/master/src/components/wistia_embed.js
Expand All @@ -35,44 +40,53 @@ class Video extends React.Component {
onReady: video => {
video.bind('play', () => {
this.setState({videoStarted: true});
this.props.onVideoStart();
if (this.props.onVideoStart) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering whether it would be better to give onVideoStart a default value. But I don't mind it either way

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before that there wasn't even a check, it was just straight up throwing an error in the console 😅

this.props.onVideoStart();
}
return video.unbind;
});
}
});
}

render () {
if (!this.props.shouldPlay) {
return null;
}

// Provide CSS classes for anything using the video component to configure what happens before and after
// the video has played for the first time. See VideoPreview for an example.
const videoStartedClass = this.state.videoStarted ? 'iframe-video-started' : 'iframe-video-not-started';

return (
<div className={classNames('video-player', this.props.className)}>
<iframe
allowFullScreen
className={classNames('wistia_embed', `wistia_async_${this.props.videoId}`, videoStartedClass)}
frameBorder="0" // deprecated attribute
height={this.props.height}
scrolling="no" // deprecated attribute
src={`https://fast.wistia.net/embed/iframe/${this.props.videoId}?seo=false&videoFoam=true&autoplay=true`}
title={this.props.title}
width={this.props.width}
height={this.props.height}
/>
</div>
);
}
}

Video.defaultProps = {
height: '225',
title: '',
width: '400'
width: '400',
shouldPlay: true
};

Video.propTypes = {
className: PropTypes.string,
height: PropTypes.string.isRequired,
onVideoStart: PropTypes.func,
shouldPlay: PropTypes.bool.isRequired,
title: PropTypes.string.isRequired,
videoId: PropTypes.string.isRequired,
width: PropTypes.string.isRequired
Expand Down
Loading