Skip to content

Commit d952a2c

Browse files
committed
fix(WebVTT): Fix times when using HLS without X-TIMESTAMP-MAP (#9313)
1 parent 724bcdc commit d952a2c

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

lib/text/vtt_text_parser.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ shaka.text.VttTextParser = class {
8787
// Only use 'X-TIMESTAMP-MAP' with HLS.
8888
if (blocks[0].includes('X-TIMESTAMP-MAP')) {
8989
offset = this.computeHlsOffset_(blocks[0], time);
90-
} else if (time.periodStart && time.vttOffset == time.periodStart) {
91-
// In the case where X-TIMESTAMP-MAP is not used and it is HLS, we
92-
// should not use offset unless segment-relative times are used.
93-
offset = 0;
9490
}
9591
}
9692

@@ -398,6 +394,10 @@ shaka.text.VttTextParser = class {
398394
start += timeOffset;
399395
end += timeOffset;
400396

397+
if (start < 0) {
398+
start = 0;
399+
}
400+
401401
// Get the payload.
402402
const payload = text.slice(1).join('\n').trim();
403403

test/hls/hls_parser_integration.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,12 @@ describe('HlsParser', () => {
138138

139139
const cues = video.textTracks[0].cues;
140140
expect(cues.length).toBe(3);
141-
expect(cues[0].startTime).toBeCloseTo(0.6, 0);
142-
expect(cues[0].endTime).toBeCloseTo(2.88, 0);
143-
expect(cues[1].startTime).toBeCloseTo(2.88, 0);
144-
expect(cues[1].endTime).toBeCloseTo(6.36, 0);
145-
expect(cues[2].startTime).toBeCloseTo(6.36, 0);
146-
expect(cues[2].endTime).toBeCloseTo(10.68, 0);
141+
expect(cues[0].startTime).toBeCloseTo(0, 0);
142+
expect(cues[0].endTime).toBeCloseTo(1.48, 0);
143+
expect(cues[1].startTime).toBeCloseTo(1.48, 0);
144+
expect(cues[1].endTime).toBeCloseTo(4.96, 0);
145+
expect(cues[2].startTime).toBeCloseTo(4.96, 0);
146+
expect(cues[2].endTime).toBeCloseTo(9.28, 0);
147147

148148
await player.unload();
149149
});

0 commit comments

Comments
 (0)