diff --git a/src/util/text-tracks.js b/src/util/text-tracks.js index cd4e74021..699c26d1c 100644 --- a/src/util/text-tracks.js +++ b/src/util/text-tracks.js @@ -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, diff --git a/test/util/text-tracks.test.js b/test/util/text-tracks.test.js index 60ae1be51..8951e8ab2 100644 --- a/test/util/text-tracks.test.js +++ b/test/util/text-tracks.test.js @@ -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' + ); +});