Skip to content

Commit

Permalink
Fix: Fix scenario where skills are present with no transcript (#824)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Press authored Jul 23, 2018
1 parent 964cd36 commit 26b8c9b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/lib/viewers/media/DashViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
27 changes: 27 additions & 0 deletions src/lib/viewers/media/__tests__/DashViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()', () => {
Expand Down

0 comments on commit 26b8c9b

Please sign in to comment.