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

feat(FEC-10817): expose the current time of the video element in live streams #589

Merged
merged 15 commits into from
Jun 17, 2021
Merged
3 changes: 3 additions & 0 deletions src/components/engine-connector/engine-connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class EngineConnector extends Component {

eventManager.listen(player, player.Event.DURATION_CHANGE, () => {
this.props.updateDuration(player.duration);
if (player.isLive()) {
this.props.updateLiveDuration(player.liveDuration);
}
});

eventManager.listen(player, player.Event.LOADED_DATA, () => {
Expand Down
7 changes: 4 additions & 3 deletions src/components/live-tag/live-tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,14 @@ class LiveTag extends Component {
/**
* render live tag component
*
* @param {*} props - component props
* @returns {React$Element} component element
* @memberof LiveTag
*/
render(props: any): React$Element<any> {
render(): React$Element<any> {
const tagStyleClass = [style.liveTag];
if (props.isDvr && !this.isOnLiveEdge()) tagStyleClass.push(style.nonLivePlayhead);
Copy link
Contributor

Choose a reason for hiding this comment

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

why isDvr removed? if needed so remove it from mapStateToProps as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you are out-of-sync (paused for example) also on live without DVR, we would like to see indication on the live tag.

Copy link
Contributor

Choose a reason for hiding this comment

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

this is new behavior. how is related to this change?

Copy link
Contributor Author

@dan-ziv dan-ziv Jun 17, 2021

Choose a reason for hiding this comment

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

Now the calculation is different so we can support it as part of this change. Like before it's just a bug.

if (!this.isOnLiveEdge()) {
tagStyleClass.push(style.nonLivePlayhead);
}

return (
<div tabIndex="0" className={tagStyleClass.join(' ')} onClick={this.onClick} onKeyDown={this.onKeyDown}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {withEventDispatcher} from 'components/event-dispatcher';
const mapStateToProps = state => ({
currentTime: state.seekbar.currentTime,
virtualTime: state.seekbar.virtualTime,
duration: state.engine.duration,
liveDuration: state.engine.liveDuration,
isDraggingActive: state.seekbar.draggingActive,
isMobile: state.shell.isMobile,
poster: state.engine.poster,
Expand Down Expand Up @@ -54,15 +54,6 @@ class SeekBarLivePlaybackContainer extends Component {
});
}

/**
*
* @returns {number} - the currentTime of the video to show
* @memberof SeekBarLivePlaybackContainer
*/
get currentTime(): number {
return Math.min(this.props.currentTime, this.props.duration);
}

/**
* render component
*
Expand All @@ -81,8 +72,9 @@ class SeekBarLivePlaybackContainer extends Component {
showTimeBubble={this.props.showTimeBubble}
changeCurrentTime={time => {
// avoiding exiting live edge by mistake in case currentTime is just a bit smaller than duration
if (!(this.props.player.isOnLiveEdge() && time === this.props.duration)) {
this.props.player.currentTime = time;
const origTime = time + this.props.player.getStartTimeOfDvrWindow();
if (!(this.props.player.isOnLiveEdge() && origTime === this.props.liveDuration)) {
this.props.player.currentTime = origTime;
}
}}
playerPoster={this.props.poster}
Expand All @@ -92,12 +84,13 @@ class SeekBarLivePlaybackContainer extends Component {
updateCurrentTime={data => this.props.updateCurrentTime(data)}
updateVirtualTime={data => this.props.updateVirtualTime(data)}
isDvr={this.props.isDvr}
currentTime={this.currentTime}
currentTime={this.props.currentTime - this.props.player.getStartTimeOfDvrWindow()}
virtualTime={this.props.virtualTime}
duration={this.props.duration}
duration={this.props.liveDuration - this.props.player.getStartTimeOfDvrWindow()}
isDraggingActive={this.props.isDraggingActive}
isMobile={this.props.isMobile}
notifyChange={payload => this.props.notifyChange(payload)}
forceFullProgress={this.props.player.isOnLiveEdge()}
/>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/seekbar/seekbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ class SeekBar extends Component {
*/
render(props: any, state: Object): React$Element<any> {
const virtualProgressWidth = `${(props.virtualTime / props.duration) * 100}%`;
const progressWidth = `${(props.currentTime / props.duration) * 100}%`;
const progressWidth = `${props.forceFullProgress ? 100 : (props.currentTime / props.duration) * 100}%`;
Copy link
Contributor

Choose a reason for hiding this comment

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

why is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now the live time is linear and duration is always bigger than the current time. For that reason you will see unfulfilled progress on the progress bar's edge. When we are on live edge this has no meaning so we would like to see full progress.

const bufferedWidth = `${Math.round(this.getBufferedPercent())}%`;
const seekbarStyleClass = [style.seekBar];
if (props.adBreak) seekbarStyleClass.push(style.adBreak);
Expand Down
9 changes: 9 additions & 0 deletions src/reducers/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const types = {
UPDATE_IS_PLAYBACK_ENDED: `${component}/UPDATE_IS_PLAYBACK_ENDED`,
UPDATE_CURRENT_TIME: `${component}/UPDATE_CURRENT_TIME`,
UPDATE_DURATION: `${component}/UPDATE_DURATION`,
UPDATE_LIVE_DURATION: `${component}/UPDATE_LIVE_DURATION`,
UPDATE_VOLUME: `${component}/UPDATE_VOLUME`,
UPDATE_MUTED: `${component}/UPDATE_MUTED`,
UPDATE_METADATA_LOADING_STATUS: `${component}/UPDATE_METADATA_LOADING_STATUS`,
Expand Down Expand Up @@ -69,6 +70,7 @@ export const initialState = {
currentTime: 0,
lastSeekPoint: 0,
duration: 0,
liveDuration: 0,
volume: 1,
muted: false,
videoTracks: [],
Expand Down Expand Up @@ -179,6 +181,12 @@ export default (state: Object = initialState, action: Object) => {
duration: action.duration
};

case types.UPDATE_LIVE_DURATION:
return {
...state,
liveDuration: action.liveDuration
};

case types.UPDATE_VOLUME:
return {
...state,
Expand Down Expand Up @@ -383,6 +391,7 @@ export const actions = {
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}),
updateLiveDuration: (liveDuration: number) => ({type: types.UPDATE_LIVE_DURATION, liveDuration}),
updateVolume: (volume: number) => ({type: types.UPDATE_VOLUME, volume}),
updateMuted: (muted: boolean) => ({type: types.UPDATE_MUTED, muted}),
updateMetadataLoadingStatus: (metadataLoaded: boolean) => ({
Expand Down
2 changes: 1 addition & 1 deletion translations/fr_ca.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@
"overlay_text": "Lecture en mode Picture-in-picture"
}
}
}s
}