Skip to content
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

Merged
merged 3 commits into from
Jul 26, 2018
Merged

Chore: Support auto captions in legacy and edited captions #825

merged 3 commits into from
Jul 26, 2018

Conversation

jeremypress
Copy link
Contributor

Will add tests/cleanup tomorrow

@boxcla
Copy link

boxcla commented Jul 25, 2018

Verified that @jeremypress has signed the CLA. Thanks for the pull request!

if (!skillsCards) {
return;
parseTextCues(transcriptCards) {
if (!transcriptCards) {
Copy link
Collaborator

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 = [])?

*
* @return {void}
* @param {Object} transcriptCards - Transcript cards
Copy link
Collaborator

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.

* @param {Object} skillsData - updated skills data
* @return {void}
*/
editAutoGeneratedCaptions(skillsData) {
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

this.autoCaptionDisplayer.append(textCues);
this.player.configure({ textDisplayFactory: this.autoCaptionDisplayer });
if (areAutoCaptionsVisible) {
this.autoCaptionDisplayer.setTextVisibility(true);
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@JustinHoldstock JustinHoldstock left a 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?

}

const transcriptCard = skillsCards.find((card) => card.skill_card_type === 'transcript');
const textCues = [];
Copy link
Contributor

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?

this.skillsData = skillsData;

const textCues = this.parseTextCues(skillsCards);

if (textCues.length > 0) {
this.autoCaptionDisplayer = new shaka.text.SimpleTextDisplayer(this.mediaEl);
Copy link
Contributor

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(...)


const textCues = this.parseTextCues(skillsData);

if (textCues.length > 0) {
Copy link
Contributor

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?

createTextCues(transcriptCard) {
const entries = getProp(transcriptCard, 'entries', []);
const textCues = [];

entries.forEach((entry) => {
Copy link
Collaborator

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.

@jeremypress jeremypress merged commit 7b23933 into box:master Jul 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants