Skip to content

Commit 9689774

Browse files
committed
fix(WebVTT): Fix times when using HLS without X-TIMESTAMP-MAP (#9313)
1 parent 347f895 commit 9689774

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
@@ -136,12 +136,12 @@ describe('HlsParser', () => {
136136

137137
const cues = video.textTracks[0].cues;
138138
expect(cues.length).toBe(3);
139-
expect(cues[0].startTime).toBeCloseTo(0.6, 0);
140-
expect(cues[0].endTime).toBeCloseTo(2.88, 0);
141-
expect(cues[1].startTime).toBeCloseTo(2.88, 0);
142-
expect(cues[1].endTime).toBeCloseTo(6.36, 0);
143-
expect(cues[2].startTime).toBeCloseTo(6.36, 0);
144-
expect(cues[2].endTime).toBeCloseTo(10.68, 0);
139+
expect(cues[0].startTime).toBeCloseTo(0, 0);
140+
expect(cues[0].endTime).toBeCloseTo(1.48, 0);
141+
expect(cues[1].startTime).toBeCloseTo(1.48, 0);
142+
expect(cues[1].endTime).toBeCloseTo(4.96, 0);
143+
expect(cues[2].startTime).toBeCloseTo(4.96, 0);
144+
expect(cues[2].endTime).toBeCloseTo(9.28, 0);
145145

146146
await player.unload();
147147
});

0 commit comments

Comments
 (0)