Skip to content

Commit

Permalink
feat: change media (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Ziv committed Oct 15, 2017
1 parent 491d351 commit 6c5c2c4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 14 deletions.
4 changes: 4 additions & 0 deletions src/components/engine-connector/engine-connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class EngineConnector extends BaseComponent {
componentDidMount() {
const TrackType = this.player.Track;

this.player.addEventListener(this.player.Event.CHANGE_SOURCE_ENDED, () => {
this.props.updatePlayerPoster(this.player.poster);
});

this.player.addEventListener(this.player.Event.PLAYER_STATE_CHANGED, (e) => {
this.props.updatePlayerState(e.payload.oldState.type, e.payload.newState.type);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class PrePlaybackPlayOverlay extends BaseComponent {
*/
constructor(obj: Object) {
super({name: 'PrePlaybackPlayOverlay', player: obj.player});
this.player.addEventListener(this.player.Event.CHANGE_SOURCE_ENDED, () => this._onChangeSourceEnded());
}

/**
Expand All @@ -53,15 +54,13 @@ class PrePlaybackPlayOverlay extends BaseComponent {

try {
this.autoplay = this.player.config.playback.autoplay;
}
catch (e) { // eslint-disable-line no-unused-vars
} catch (e) { // eslint-disable-line no-unused-vars
this.autoplay = false;
}

try {
this.mobileAutoplay = this.player.config.playback.mobileAutoplay;
}
catch (e) { // eslint-disable-line no-unused-vars
} catch (e) { // eslint-disable-line no-unused-vars
this.mobileAutoplay = false;
}
}
Expand All @@ -73,7 +72,7 @@ class PrePlaybackPlayOverlay extends BaseComponent {
* @memberof PrePlaybackPlayOverlay
*/
componentWillUnmount() {
this.props.updatePrePlayback(false);
this._hidePrePlayback();
this.props.removePlayerClass(style.prePlayback);
}

Expand All @@ -84,14 +83,9 @@ class PrePlaybackPlayOverlay extends BaseComponent {
* @memberof PrePlaybackPlayOverlay
*/
componentDidMount() {
this.player.addEventListener(this.player.Event.PLAY, () => {
this.props.updatePrePlayback(false);
this.props.removePlayerClass(style.prePlayback);
});

this.player.addEventListener(this.player.Event.PLAY, () => this._hidePrePlayback());
if (this.player.paused === false) {
this.props.updatePrePlayback(false);
this.props.removePlayerClass(style.prePlayback);
this._hidePrePlayback();
}
}

Expand All @@ -116,8 +110,7 @@ class PrePlaybackPlayOverlay extends BaseComponent {
}).then(() => {
this.player.play();
if (this.props.prePlayback) {
this.props.updatePrePlayback(false);
this.props.removePlayerClass(style.prePlayback);
this._hidePrePlayback();
}
}).catch((e) => {
this.logger.error(e.message);
Expand Down Expand Up @@ -147,6 +140,41 @@ class PrePlaybackPlayOverlay extends BaseComponent {
</div>
)
}

/**
* Change source ended event handler.
* @private
* @returns {void}
*/
_onChangeSourceEnded(): void {
try {
if (!this.player.config.playback.autoplay) {
this._displayPrePlayback();
}
} catch (e) {
this.logger.error(e.message);
}
}

/**
* Displays the pre playback overlay.
* @private
* @returns {void}
*/
_displayPrePlayback(): void {
this.props.updatePrePlayback(true);
this.props.addPlayerClass(style.prePlayback);
}

/**
* Hides the pre playback overlay.
* @private
* @returns {void}
*/
_hidePrePlayback(): void {
this.props.updatePrePlayback(false);
this.props.removePlayerClass(style.prePlayback);
}
}

export default PrePlaybackPlayOverlay;

0 comments on commit 6c5c2c4

Please sign in to comment.