Skip to content

Commit

Permalink
fix: hls-interstitial start-date not placed correctly (#126)
Browse files Browse the repository at this point in the history
* fix: hls-interstitial start-date not placed correctly

* update specs
  • Loading branch information
Nfrederiksen authored Dec 18, 2024
1 parent 341fe8f commit 7954238
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2824,9 +2824,10 @@ class HLSVod {

if (playlistItemWithInterstitialsMetadata(playlistItem)) {
const newDateRange = playlistItem.attributes.attributes["daterange"];
const newStartDate = new Date(newDateRange["START-DATE"]);
const tempTimeOffset = new Date(this.timeOffset);
const newStartDateString = new Date(newStartDate.getTime() + tempTimeOffset.getTime()).toISOString();
const vodsInputTimestamp = new Date(this.timeOffset);
const extraDurationSec = i == 0 && q.duration ? 0 : q.duration;
const startTimeOffsetMs = (position + extraDurationSec) * 1000;
const newStartDateString = new Date(vodsInputTimestamp.getTime() + startTimeOffsetMs).toISOString();
newDateRange["START-DATE"] = newStartDateString;
q["daterange"] = newDateRange;
}
Expand Down
30 changes: 30 additions & 0 deletions spec/hlsvod_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3809,5 +3809,35 @@ describe("HLSVod delta time and positions", () => {
});
});
});

it("with Program date time enabled and VODs have HLS Interstitial Tag", (done) => {
mockVod = new HLSVod("http://mock.com/mock.m3u8", null, Date.now(), 0, null, {
sequenceAlwaysContainNewSegments: 0,
forcedDemuxMode: true,
});
mockVod2 = new HLSVod("http://mock.com/mock2.m3u8", null, Date.now() + 90000, 0, null, {
sequenceAlwaysContainNewSegments: 0,
forcedDemuxMode: true,
});
mockVod.load(mock_vod_3.master, mock_vod_3.media, mock_vod_3.audio).then(() => {
mockVod2.loadAfter(mockVod, mock_vod_3.master, mock_vod_3.media, mock_vod_3.audio).then(() => {
let m3u8 = mockVod2.getLiveMediaAudioSequences(0, "audio-aacl-256", "sv", 4);
let lines = m3u8.split("\n");
expect(
lines[16].includes('#EXT-X-DATERANGE:ID="ad1",CLASS="com.apple.hls.interstitial",START-DATE') &&
lines[16].includes(
',DURATION="15.0",X-ASSET-URI="http://example.com/ad1.m3u8",X-RESUME-OFFSET="0",X-RESTRICT="SKIP,JUMP",X-COM-EXAMPLE-BEACON="123"'
)
).toBe(true);
expect(
lines[17].includes('#EXT-X-DATERANGE:ID="ad1",CLASS="com.apple.hls.interstitial",START-DATE') &&
lines[16].includes(
',DURATION="15.0",X-ASSET-URI="http://example.com/ad1.m3u8",X-RESUME-OFFSET="0",X-RESTRICT="SKIP,JUMP",X-COM-EXAMPLE-BEACON="123"'
)
).toBe(false);
done();
});
});
});
});
});

0 comments on commit 7954238

Please sign in to comment.