Skip to content

Commit

Permalink
fix: error on undefined metadata frames (#1383)
Browse files Browse the repository at this point in the history
* fix: error on undefined metadata frames

* add test

* additional test
  • Loading branch information
adrums86 authored Mar 23, 2023
1 parent 915bdee commit d258fae
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/util/text-tracks.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ export const addMetadata = ({
return;
}

// If we have no frames, we can't create a cue.
if (!metadata.frames || !metadata.frames.length) {
return;
}

metadata.frames.forEach((frame) => {
const cue = new Cue(
time,
Expand Down
35 changes: 35 additions & 0 deletions test/util/text-tracks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,38 @@ test('creates cues for timed metadata', function(assert) {
'added one metadata cues'
);
});

test('does nothing if frames are undefined', function(assert) {
addMetadata({
inbandTextTracks: this.inbandTextTracks,
timestampOffset: this.timestampOffset,
videoDuration: 1,
metadataArray: [{
cueTime: 1
}]
});

assert.strictEqual(
this.inbandTextTracks.metadataTrack_.cues.length,
0,
'added no metadata cues'
);
});

test('does nothing if frames.length is 0', function(assert) {
addMetadata({
inbandTextTracks: this.inbandTextTracks,
timestampOffset: this.timestampOffset,
videoDuration: 1,
metadataArray: [{
cueTime: 1,
frames: []
}]
});

assert.strictEqual(
this.inbandTextTracks.metadataTrack_.cues.length,
0,
'added no metadata cues'
);
});

0 comments on commit d258fae

Please sign in to comment.