Skip to content

Commit

Permalink
refactor: add dateTimeObject and dateTimeString to Cues for backward …
Browse files Browse the repository at this point in the history
…compatibility (#1409)
  • Loading branch information
harisha-swaminathan authored Jul 24, 2023
1 parent 3c5a5bc commit 2079454
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/segment-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -3180,6 +3180,11 @@ export default class SegmentLoader extends videojs.EventTarget {
const Cue = window.WebKitDataCue || window.VTTCue;
const value = {
custom: segment.custom,
// Since we now have programDateTime available for every segment, dateTimeObject and dateTimeString
// are redundant
// TODO: Consider removing this in future major version
dateTimeObject: segment.programDateTime ? new Date(segment.programDateTime) : undefined,
dateTimeString: segment.programDateTime ? new Date(segment.programDateTime).toISOString() : undefined,
programDateTime: segment.programDateTime,
bandwidth: segmentInfo.playlist.attributes.BANDWIDTH,
resolution: segmentInfo.playlist.attributes.RESOLUTION,
Expand Down
6 changes: 3 additions & 3 deletions src/util/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ export const findSegmentForProgramTime = (programTime, playlist) => {

let segment = playlist.segments[0];

if (dateTimeObject < segment.programDateTime) {
if (dateTimeObject < new Date(segment.programDateTime)) {
// Requested time is before stream start.
return null;
}

for (let i = 0; i < playlist.segments.length - 1; i++) {
segment = playlist.segments[i];

const nextSegmentStart = playlist.segments[i + 1].programDateTime;
const nextSegmentStart = new Date(playlist.segments[i + 1].programDateTime);

if (dateTimeObject < nextSegmentStart) {
break;
Expand All @@ -102,7 +102,7 @@ export const findSegmentForProgramTime = (programTime, playlist) => {
return null;
}

if (dateTimeObject > lastSegmentStart) {
if (dateTimeObject > new Date(lastSegmentStart)) {
segment = lastSegment;
}

Expand Down

0 comments on commit 2079454

Please sign in to comment.