Commit 246798b6 authored by seotts's avatar seotts

Use “play” event listener; clean-up code

parent 785386b1
...@@ -45,7 +45,7 @@ class VideoPreview extends React.Component { ...@@ -45,7 +45,7 @@ class VideoPreview extends React.Component {
height={this.props.videoHeight} height={this.props.videoHeight}
videoId={this.props.videoId} videoId={this.props.videoId}
width={this.props.videoWidth} width={this.props.videoWidth}
onLoad={this.handleVideoLoaded} onVideoStart={this.handleVideoLoaded}
/> />
</div> </div>
) : ( ) : (
...@@ -53,6 +53,7 @@ class VideoPreview extends React.Component { ...@@ -53,6 +53,7 @@ class VideoPreview extends React.Component {
className="video-thumbnail" className="video-thumbnail"
onClick={this.handleShowVideo} onClick={this.handleShowVideo}
> >
{/* Load an invisible spinner so that the image has a chance to load before it's needed */}
<img <img
className={classNames('loading-spinner', 'hidden-spinner')} className={classNames('loading-spinner', 'hidden-spinner')}
src="/svgs/modal/spinner-white.svg" src="/svgs/modal/spinner-white.svg"
......
...@@ -46,10 +46,10 @@ ...@@ -46,10 +46,10 @@
position: relative; position: relative;
} }
.iframe-not-loaded { .iframe-video-not-started {
visibility: hidden; visibility: hidden;
} }
.iframe-loaded { .iframe-video-started {
visibility: visible; visibility: visible;
} }
const bindAll = require('lodash.bindall');
const PropTypes = require('prop-types'); const PropTypes = require('prop-types');
const React = require('react'); const React = require('react');
const classNames = require('classnames'); const classNames = require('classnames');
...@@ -11,7 +9,7 @@ class Video extends React.Component { ...@@ -11,7 +9,7 @@ class Video extends React.Component {
super(props); super(props);
this.state = { this.state = {
loaded: false videoStarted: false
}; };
} }
componentDidMount () { componentDidMount () {
...@@ -29,36 +27,37 @@ class Video extends React.Component { ...@@ -29,36 +27,37 @@ class Video extends React.Component {
} }
window._wq = window._wq || []; window._wq = window._wq || [];
// Use onReady in combination with the Wistia 'play' event handler so that onVideoStart()
// isn't called until the video actually starts. onReady fires before the video player is visible.
window._wq.push({ window._wq.push({
id: this.props.videoId, id: this.props.videoId,
onReady: video => { onReady: video => {
video.bind('secondchange', s => { video.bind('play', () => {
if (s >= 0) { this.setState({videoStarted: true});
this.setState({loaded: true}); this.props.onVideoStart();
this.props.onLoad(); return video.unbind;
}
}); });
} }
}); });
} }
render () { render () {
const loadedClass = this.state.loaded ? 'iframe-loaded' : 'iframe-not-loaded'; // 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 ( return (
<div className={classNames('video-player', this.props.className)}> <div className={classNames('video-player', this.props.className)}>
<iframe <iframe
allowFullScreen allowFullScreen
// allowFullScreen is legacy, can we start using allow='fullscreen'? className={classNames('wistia_embed', `wistia_async_${this.props.videoId}`, videoStartedClass)}
// allow="fullscreen"
className={classNames('wistia_embed', `wistia_async_${this.props.videoId}`, loadedClass)}
frameBorder="0" // deprecated attribute frameBorder="0" // deprecated attribute
height={this.props.height} height={this.props.height}
scrolling="no" // deprecated attribute scrolling="no" // deprecated attribute
src={`https://fast.wistia.net/embed/iframe/${this.props.videoId}?seo=false&videoFoam=true`} src={`https://fast.wistia.net/embed/iframe/${this.props.videoId}?seo=false&videoFoam=true`}
title={this.props.title} title={this.props.title}
width={this.props.width} width={this.props.width}
// onLoad={this.props.onLoad}
/> />
</div> </div>
); );
...@@ -73,7 +72,7 @@ Video.defaultProps = { ...@@ -73,7 +72,7 @@ Video.defaultProps = {
Video.propTypes = { Video.propTypes = {
className: PropTypes.string, className: PropTypes.string,
height: PropTypes.string.isRequired, height: PropTypes.string.isRequired,
onLoad: PropTypes.func, onVideoStart: PropTypes.func,
title: PropTypes.string.isRequired, title: PropTypes.string.isRequired,
videoId: PropTypes.string.isRequired, videoId: PropTypes.string.isRequired,
width: PropTypes.string.isRequired width: PropTypes.string.isRequired
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment