Skip to content

Commit

Permalink
Fix: Stop Using Previous VOD to Set timeOffset (#119)
Browse files Browse the repository at this point in the history
* Reset timeOffset when loading next vod

* test: update for timeOffset
  • Loading branch information
Nfrederiksen committed Sep 13, 2023
1 parent e6a0ad0 commit 1b97073
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
5 changes: 1 addition & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1930,10 +1930,7 @@ class HLSVod {
this.segments[destBw].push(q);
}
}
const lastSeg = this.segments[sourceBw][this.segments[sourceBw].length - 1];
if (this.timeOffset !== null && lastSeg && lastSeg.timelinePosition) {
this.timeOffset = lastSeg.timelinePosition + lastSeg.duration * 1000;
}

this.segments[destBw].push({
discontinuity: true,
daterange: this.rangeMetadata ? this.rangeMetadata : null,
Expand Down
14 changes: 8 additions & 6 deletions spec/hlsvod_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,18 +686,19 @@ describe("HLSVod with timeline", () => {


it("can handle vod after another vod", (done) => {
const VOD_LENGTH_MS = 2646000 + 6266;
const now = Date.now();
mockVod = new HLSVod("http://mock.com/mock.m3u8", [], now);
mockVod2 = new HLSVod("http://mock.com/mock2.m3u8", [], now + 1);
mockVod2 = new HLSVod("http://mock.com/mock2.m3u8", [], now + VOD_LENGTH_MS);
mockVod
.load(mockMasterManifest, mockMediaManifest)
.then(() => {
return mockVod2.loadAfter(mockVod, mockMasterManifest, mockMediaManifest);
})
.then(() => {
const seqSegments = mockVod2.getLiveMediaSequenceSegments(0);
expect(seqSegments["2497000"][4].timelinePosition).toEqual(now + 2646 * 1000);
expect(seqSegments["2497000"][6].timelinePosition).toEqual(now + 2646 * 1000 + 6266);
expect(seqSegments["2497000"][4].timelinePosition).toEqual(now + VOD_LENGTH_MS - 6266);
expect(seqSegments["2497000"][6].timelinePosition).toEqual(now + VOD_LENGTH_MS);
done();
});
});
Expand Down Expand Up @@ -755,17 +756,18 @@ describe("HLSVod with timeline", () => {
},
];
const now = Date.now();
const VOD_LENGTH_MS = 2646000 + 6266;
mockVod = new HLSVod("http://mock.com/mock.m3u8", [], now);
mockVod2 = new HLSVod("http://mock.com/mock2.m3u8", splices, now + 1);
mockVod2 = new HLSVod("http://mock.com/mock2.m3u8", splices, now + VOD_LENGTH_MS);
mockVod
.load(mockMasterManifest, mockMediaManifest)
.then(() => {
return mockVod2.loadAfter(mockVod, mockMasterManifest, mockMediaManifest);
})
.then(() => {
const seqSegments = mockVod2.getLiveMediaSequenceSegments(0);
expect(seqSegments["2497000"][4].timelinePosition).toEqual(now + 2646 * 1000);
expect(seqSegments["2497000"][6].timelinePosition).toEqual(now + 2646 * 1000 + 6266);
expect(seqSegments["2497000"][4].timelinePosition).toEqual(now + VOD_LENGTH_MS - 6266);
expect(seqSegments["2497000"][6].timelinePosition).toEqual(now + VOD_LENGTH_MS);
done();
});
});
Expand Down

0 comments on commit 1b97073

Please sign in to comment.