这是indexloc提供的服务,不要输入任何密码
Skip to content

🐛Propagate <track> elements in amp-story #13751

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

Merged
merged 1 commit into from
Mar 5, 2018

Conversation

iefserge
Copy link
Contributor

@iefserge iefserge commented Mar 1, 2018

Work-in-progress attempt to propagate amp-video <track> tags to enable subtitles in stories.
Should resolve #13698.

Simply moving existing <track>(s) doesn't seem to work, so this code creates new elements and adds those to the video.
In addition it has to wait for loadedmetadata for subtitles to show in Firefox.

Tested on:
Desktop: Chrome, Safari, Firefox
Mobile: Safari

I'd like some feedback if this approach makes sense, before adding tests/examples etc.

@googlebot
Copy link

Thanks for your pull request. t looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers
  • Your company has a Point of Contact who decides which employees are authorized to participate. Ask your POC to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the project maintainer to go/cla#troubleshoot.
  • The email used to register you as an authorized contributor must be the email used for the Git commit. Check your existing CLA data and verify that your email is set on your git commits.
  • The email used to register you as an authorized contributor must also be attached to your GitHub account.

@@ -48,6 +50,31 @@ export class Sources {
element.setAttribute('src', this.srcAttr_);
}

// Wait for "loadedmetadata" before adding tracks
// Firefox issue workaround
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add more insight on what the issue is in Firefox?

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 sure

@@ -48,6 +50,31 @@ export class Sources {
element.setAttribute('src', this.srcAttr_);
}

// Wait for "loadedmetadata" before adding tracks
// Firefox issue workaround
const addTracksHandler = () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to move this up outside of the class so that it's only declared once, rather than on every invocation of applyToElement(...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function uses this.trackEls to apply tracks, but inner forEach call can be moved outside to its own method in the class

this.applyTracksToElement_(element);
};

element.addEventListener('loadedmetadata', addTracksHandler);
Copy link
Contributor

@newmuis newmuis Mar 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be a race condition? What happens if the loadedmetadata event is fired before applyTracksToElement_ is called?

Maybe you can check first, like:

if (element.readyState >= 1 /* HAVE_METADATA */) {
  this.applyTracksToElement_(element);
} else {
  element.addEventListener('loadedmetadata', addTracksHandler);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch, thank you!

element.addEventListener('loadedmetadata', addTracksHandler);
}
}

Array.prototype.forEach.call(this.srcEls_,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can you move this above the tracks block, to keep it together with the logic for the src attribute?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@iefserge iefserge force-pushed the story-video-track branch from a1719fa to 4c14db8 Compare March 2, 2018 22:33
@iefserge iefserge force-pushed the story-video-track branch from 4c14db8 to a4c5844 Compare March 2, 2018 22:35
@iefserge
Copy link
Contributor Author

iefserge commented Mar 2, 2018

@googlebot I signed it!

@iefserge iefserge force-pushed the story-video-track branch from 5d6f589 to 528839d Compare March 5, 2018 19:54
@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes and removed cla: no labels Mar 5, 2018
@iefserge iefserge force-pushed the story-video-track branch from 528839d to a4c5844 Compare March 5, 2018 19:55
@newmuis newmuis changed the title 🐛Propagate <track> elements in amp-story [wip] 🐛Propagate <track> elements in amp-story Mar 5, 2018
@newmuis newmuis merged commit a522b64 into ampproject:master Mar 5, 2018
RanAbram pushed a commit to RanAbram/amphtml that referenced this pull request Mar 12, 2018
🐛Propagate <track> elements in amp-story
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

amp-story MediaPool does not propagate <track> elements
3 participants