Skip to content

Commit

Permalink
fix(): countdown skips the postroll (#294)
Browse files Browse the repository at this point in the history
* listen to `PLAYBACK_ENDED` instead of `ENDED`
* revert #291 since it not needed any more
  • Loading branch information
yairans committed Nov 8, 2018
1 parent 7271bd2 commit 89e8d9a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/components/engine-connector/engine-connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class EngineConnector extends BaseComponent {
this.props.updateAdIsPlaying(false);
this.props.updateIsPlaying(false);
this.props.updateIsEnded(false);
this.props.updateIsPlaybackEnded(false);
this.props.updateLastSeekPoint(0);
this.props.updateCurrentTime(0);
if (this.props.engine.isCasting) {
this.props.updateLoadingSpinnerState(true);
}
Expand Down Expand Up @@ -109,6 +109,7 @@ class EngineConnector extends BaseComponent {
this.eventManager.listen(this.player, this.player.Event.PLAY, () => {
this.props.updateIsPlaying(true);
this.props.updateIsEnded(false);
this.props.updateIsPlaybackEnded(false);
});

this.eventManager.listen(this.player, this.player.Event.PAUSE, () => {
Expand All @@ -126,6 +127,10 @@ class EngineConnector extends BaseComponent {
this.props.updateIsPaused(true);
});

this.eventManager.listen(this.player, this.player.Event.PLAYBACK_ENDED, () => {
this.props.updateIsPlaybackEnded(true);
});

this.eventManager.listen(this.player, this.player.Event.TRACKS_CHANGED, () => {
let audioTracks = this.player.getTracks(TrackType.AUDIO);
let videoTracks = this.player.getTracks(TrackType.VIDEO);
Expand Down
6 changes: 2 additions & 4 deletions src/components/playlist-countdown/playlist-countdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const mapStateToProps = state => ({
currentTime: state.engine.currentTime,
duration: state.engine.duration,
lastSeekPoint: state.engine.lastSeekPoint,
isEnded: state.engine.isEnded
isPlaybackEnded: state.engine.isPlaybackEnded
});

@connect(mapStateToProps)
Expand Down Expand Up @@ -109,9 +109,7 @@ class PlaylistCountdown extends BaseComponent {
const countdown = this.player.playlist.countdown;
if (
!this.state.canceled &&
(this.props.isEnded ||
this.props.currentTime >= timeToShow + countdown.duration ||
(this.props.duration && this.props.currentTime >= this.props.duration))
(this.props.isPlaybackEnded || (this.props.currentTime >= timeToShow + countdown.duration && this.props.currentTime < this.props.duration))
) {
this.player.playlist.playNext();
}
Expand Down
9 changes: 9 additions & 0 deletions src/reducers/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const types = {
UPDATE_LAST_SEEK_POINT: `${component}/UPDATE_LAST_SEEK_POINT`,
UPDATE_IS_CHANGING_SOURCE: `${component}/UPDATE_IS_CHANGING_SOURCE`,
UPDATE_IS_ENDED: `${component}/UPDATE_IS_ENDED`,
UPDATE_IS_PLAYBACK_ENDED: `${component}/UPDATE_IS_PLAYBACK_ENDED`,
UPDATE_CURRENT_TIME: `${component}/UPDATE_CURRENT_TIME`,
UPDATE_DURATION: `${component}/UPDATE_DURATION`,
UPDATE_VOLUME: `${component}/UPDATE_VOLUME`,
Expand Down Expand Up @@ -47,6 +48,7 @@ export const initialState = {
isPlaying: false,
isPaused: false,
isEnded: false,
isPlaybackEnded: false,
isChangingSource: false,
metadataLoaded: false,
playerState: {
Expand Down Expand Up @@ -129,6 +131,12 @@ export default (state: Object = initialState, action: Object) => {
isEnded: action.isEnded
};

case types.UPDATE_IS_PLAYBACK_ENDED:
return {
...state,
isPlaybackEnded: action.isPlaybackEnded
};

case types.UPDATE_CURRENT_TIME:
return {
...state,
Expand Down Expand Up @@ -321,6 +329,7 @@ export const actions = {
updateIsPaused: (isPaused: boolean) => ({type: types.UPDATE_IS_PAUSED, isPaused}),
updateLastSeekPoint: (lastSeekPoint: number) => ({type: types.UPDATE_LAST_SEEK_POINT, lastSeekPoint}),
updateIsEnded: (isEnded: boolean) => ({type: types.UPDATE_IS_ENDED, isEnded}),
updateIsPlaybackEnded: (isPlaybackEnded: boolean) => ({type: types.UPDATE_IS_PLAYBACK_ENDED, isPlaybackEnded}),
updateCurrentTime: (currentTime: number) => ({type: types.UPDATE_CURRENT_TIME, currentTime}),
updateDuration: (duration: number) => ({type: types.UPDATE_DURATION, duration}),
updateVolume: (volume: number) => ({type: types.UPDATE_VOLUME, volume}),
Expand Down

0 comments on commit 89e8d9a

Please sign in to comment.