Skip to content

Commit

Permalink
fix: log correct time and duration for video subsections
Browse files Browse the repository at this point in the history
If a subsection of a video is added to a course using advanced settings, show and log correct start and end times to the users.
  • Loading branch information
a-asad committed Dec 11, 2024
1 parent aeddb8a commit 2762cfc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
11 changes: 9 additions & 2 deletions xmodule/js/src/video/04_video_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,17 @@
}

function updateVcrVidTime(params) {
var endTime = (this.config.endTime !== null) ? this.config.endTime : params.duration;
var endTime = (this.config.endTime !== null) ? this.config.endTime : params.duration,
startTime, currentTime;
// in case endTime is accidentally specified as being greater than the video
endTime = Math.min(endTime, params.duration);
this.videoControl.vidTimeEl.text(Time.format(params.time) + ' / ' + Time.format(endTime));
startTime = this.config.startTime > 0 ? this.config.startTime : 0;
// if it's a subsection of video, use the clip duration as endTime
if (startTime && this.config.endTime) {
endTime = this.config.endTime - startTime;
}
currentTime = startTime ? params.time - startTime : params.time;
this.videoControl.vidTimeEl.text(Time.format(currentTime) + ' / ' + Time.format(endTime));
}
}
);
Expand Down
17 changes: 14 additions & 3 deletions xmodule/js/src/video/09_events_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,15 @@
},

getCurrentTime: function() {
var player = this.state.videoPlayer;
return player ? player.currentTime : 0;
var player = this.state.videoPlayer,
startTime = this.state.config.startTime,
currentTime;
currentTime = player ? player.currentTime : 0;
// if video didn't start from 0(it's a subsection of video), subtract the additional time at start
if (startTime) {
currentTime = currentTime ? currentTime - startTime : 0;
}
return currentTime;
},

getCurrentLanguage: function() {
Expand All @@ -153,11 +160,15 @@
},

log: function(eventName, data) {
// use startTime and endTime to calculate the duration to handle the case where only a subsection of video is used
var endTime = this.state.config.endTime || this.state.duration,
startTime = this.state.config.startTime;

var logInfo = _.extend({
id: this.state.id,
// eslint-disable-next-line no-nested-ternary
code: this.state.isYoutubeType() ? this.state.youtubeId() : this.state.canPlayHLS ? 'hls' : 'html5',
duration: this.state.duration
duration: endTime - startTime
}, data, this.options.data);
Logger.log(eventName, logInfo);
}
Expand Down

0 comments on commit 2762cfc

Please sign in to comment.