-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chore: Support auto captions in legacy and edited captions #825
Conversation
Verified that @jeremypress has signed the CLA. Thanks for the pull request! |
src/lib/viewers/media/DashViewer.js
Outdated
if (!skillsCards) { | ||
return; | ||
parseTextCues(transcriptCards) { | ||
if (!transcriptCards) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use default parameter values for these functions in order to cut down on some of the guard clauses? Something like parseTextCues(transcriptCards = [])
?
src/lib/viewers/media/DashViewer.js
Outdated
* | ||
* @return {void} | ||
* @param {Object} transcriptCards - Transcript cards |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be @param {Array}
? It looks like .find
is used on it below.
src/lib/viewers/media/DashViewer.js
Outdated
* @param {Object} skillsData - updated skills data | ||
* @return {void} | ||
*/ | ||
editAutoGeneratedCaptions(skillsData) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like there's some duplication between this function and loadAutoGeneratedCaptions
. Should there be a third method that both of these call? I also think update
might be more clear than edit
, since no explicit user interaction is involved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, will clean up in the next commit. Agreed that's a better name.
src/lib/viewers/media/DashViewer.js
Outdated
this.autoCaptionDisplayer.append(textCues); | ||
this.player.configure({ textDisplayFactory: this.autoCaptionDisplayer }); | ||
if (areAutoCaptionsVisible) { | ||
this.autoCaptionDisplayer.setTextVisibility(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we call this.autoCaptionDisplayer.setTextVisibility(areAutoCaptionsVisible)
to clarify that we're preserving the user's preference? What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there's any harm to calling it again with false if they are already off, and it'll make the code cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to abstract any of the autoCaptionDisplayer code to other functions, or a utility class? It may make maintenance a little bit easier. As a bonus, will allow us to be able to swap for our own, if need be. Thoughts on that?
src/lib/viewers/media/DashViewer.js
Outdated
} | ||
|
||
const transcriptCard = skillsCards.find((card) => card.skill_card_type === 'transcript'); | ||
const textCues = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since textCues
isn't being used until after the if
, why not declare it there?
src/lib/viewers/media/DashViewer.js
Outdated
this.skillsData = skillsData; | ||
|
||
const textCues = this.parseTextCues(skillsCards); | ||
|
||
if (textCues.length > 0) { | ||
this.autoCaptionDisplayer = new shaka.text.SimpleTextDisplayer(this.mediaEl); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you reuse this, if it's already been created beforehand?
IE) this.autoCaptionDisplayer = this.autoCaptionDisplayer || new SimpleTextDisplayer(...)
src/lib/viewers/media/DashViewer.js
Outdated
|
||
const textCues = this.parseTextCues(skillsData); | ||
|
||
if (textCues.length > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard to make sure that autoCaptionDisplayer
exists?
src/lib/viewers/media/DashViewer.js
Outdated
createTextCues(transcriptCard) { | ||
const entries = getProp(transcriptCard, 'entries', []); | ||
const textCues = []; | ||
|
||
entries.forEach((entry) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: If desired, you could convert this to a .map
call to avoid the temporary textCues
variable and mutation that goes with it.
Will add tests/cleanup tomorrow