From 26b8c9b350054be6c2250316d48d3e86c21c0525 Mon Sep 17 00:00:00 2001 From: Jeremy Press Date: Mon, 23 Jul 2018 16:14:11 -0700 Subject: [PATCH] Fix: Fix scenario where skills are present with no transcript (#824) --- src/lib/viewers/media/DashViewer.js | 26 +++++++++++------- .../media/__tests__/DashViewer-test.js | 27 +++++++++++++++++++ 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/src/lib/viewers/media/DashViewer.js b/src/lib/viewers/media/DashViewer.js index 68b671357..b19dddd43 100644 --- a/src/lib/viewers/media/DashViewer.js +++ b/src/lib/viewers/media/DashViewer.js @@ -469,17 +469,25 @@ class DashViewer extends VideoBaseViewer { // Convert Box Skill transcript cards to Shaka Text Cues const skillsCards = getProp(this.options, 'file.metadata.global.boxSkillsCards.cards'); - if (skillsCards) { - const transcriptCard = skillsCards.find((card) => card.skill_card_type === 'transcript'); - const entries = transcriptCard.entries || []; - entries.forEach((entry) => { - // Set defaults if transcript data is malformed (start/end: 0s, text: '') - const { appears = [{}], text = '' } = entry; - const { start = 0, end = 0 } = Array.isArray(appears) && appears.length > 0 ? appears[0] : {}; - textCues.push(new shaka.text.Cue(start, end, text)); - }); + // No skills are available on the file + if (!skillsCards) { + return; + } + + const transcriptCard = skillsCards.find((card) => card.skill_card_type === 'transcript'); + // No transcript can be found in the skills data + if (!transcriptCard) { + return; } + const entries = transcriptCard.entries || []; + entries.forEach((entry) => { + // Set defaults if transcript data is malformed (start/end: 0s, text: '') + const { appears = [{}], text = '' } = entry; + const { start = 0, end = 0 } = Array.isArray(appears) && appears.length > 0 ? appears[0] : {}; + textCues.push(new shaka.text.Cue(start, end, text)); + }); + if (textCues.length > 0) { this.autoCaptionDisplayer = new shaka.text.SimpleTextDisplayer(this.mediaEl); this.autoCaptionDisplayer.append(textCues); diff --git a/src/lib/viewers/media/__tests__/DashViewer-test.js b/src/lib/viewers/media/__tests__/DashViewer-test.js index d53813179..b238f9f98 100644 --- a/src/lib/viewers/media/__tests__/DashViewer-test.js +++ b/src/lib/viewers/media/__tests__/DashViewer-test.js @@ -862,6 +862,33 @@ describe('lib/viewers/media/DashViewer', () => { dash.loadAutoGeneratedCaptions(); }); + + it('should convert to Shaka Cues, initialize subtitles, set button label & return true if there are auto-generated subtitles', () => { + dash.options = { + file: { + metadata: { + global: { + boxSkillsCards: { + cards: [ + { + skill_card_type: 'not a transcript', + entries: [] + } + ] + } + } + } + }, + location: { + locale: 'en-US' + } + }; + stubs.mockPlayer.expects('configure').never(); + stubs.mockControls.expects('initSubtitles').never(); + stubs.mockControls.expects('setLabel').never(); + + dash.loadAutoGeneratedCaptions(); + }); }); describe('loadAlternateAudio()', () => {