Skip to content
This repository has been archived by the owner on Jan 12, 2019. It is now read-only.

don't crash when segment metadata cues can't be created #1167

Merged
merged 2 commits into from
Jun 16, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/segment-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,11 @@ export default class SegmentLoader extends videojs.EventTarget {
const start = segment.start;
const end = segment.end;

// Do not try adding the cue if the start and end times are invalid.
if (!Number.isFinite(start) || !Number.isFinite(end)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isFinite is not supported in IE. Do we have a polyfill for it?

return;
}

removeCuesFromTrack(start, end, this.segmentMetadataTrack_);

const Cue = window.WebKitDataCue || window.VTTCue;
Expand Down
16 changes: 13 additions & 3 deletions test/segment-loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ QUnit.module('SegmentLoader', function(hooks) {
'as they are buffered',
function(assert) {
const track = loader.segmentMetadataTrack_;
let playlist = playlistWithDuration(40);
let playlist = playlistWithDuration(50);
let probeResponse;
let expectedCue;

Expand Down Expand Up @@ -328,6 +328,7 @@ QUnit.module('SegmentLoader', function(hooks) {
this.requests[0].response = new Uint8Array(10).buffer;
this.requests.shift().respond(200, null, '');
this.updateend();
this.clock.tick(1);
expectedCue = {
uri: '3.ts',
timeline: 0,
Expand All @@ -340,9 +341,18 @@ QUnit.module('SegmentLoader', function(hooks) {
assert.deepEqual(track.cues[2].value, expectedCue,
'added correct segment info to cue');

// does not add cue for invalid segment timing info
probeResponse = { start: 30, end: void 0 };
this.requests[0].response = new Uint8Array(10).buffer;
this.requests.shift().respond(200, null, '');
this.updateend();
this.clock.tick(1);

assert.equal(track.cues.length, 3, 'no cue added');

// verify stats
assert.equal(loader.mediaBytesTransferred, 40, '40 bytes');
assert.equal(loader.mediaRequests, 4, '4 requests');
assert.equal(loader.mediaBytesTransferred, 50, '50 bytes');
assert.equal(loader.mediaRequests, 5, '5 requests');
});

QUnit.test('fires ended at the end of a playlist', function(assert) {
Expand Down