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

Implementation of VideoInterface for amp-gfycat player #10583

Merged
merged 17 commits into from Sep 11, 2017

Conversation

koshka
Copy link
Contributor

@koshka koshka commented Jul 21, 2017

Implementation of VideoInterface for amp-gfycat player

  • implementation of VideoInterface, autoplaying videos are paused when scrolled out of view
  • tests updated

Opened issue for this PR #10537

@@ -36,6 +36,10 @@ tags: { # <amp-gfycat>
mandatory: true
}
attrs: {
name: "autoplay"
Copy link
Contributor

Choose a reason for hiding this comment

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

minor nit: we like to keep attributes in alphabetical order. if not too much trouble, move above data-gfyid

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@honeybadgerdontcare
Copy link
Contributor

@aghassemi validation looks good.


/** @override */
isInteractive() {
return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

set this to false so you don't get the sound equalizer icon and the autoplay shim which are not needed in this component.

this.videoIframeSrc_ = null;

/** @private {?Promise} */
this.playerReadyPromise_ = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

this and playerReadyResolver_ should not be needed. See below for alternative.

buildCallback() {
this.videoid_ = this.getVideoId_();

this.playerReadyPromise_ = new Promise(resolve => {
Copy link
Contributor

Choose a reason for hiding this comment

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

remove

createPlaceholderCallback() {
const placeholder = this.win.document.createElement('amp-img');
dev().assert(this.videoid_);
const videoid = this.videoid_ || '';
Copy link
Contributor

Choose a reason for hiding this comment

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

no need to do || '' anymore since dev.assert() above ensures videoid_ is not falsy.

return this.videoIframeSrc_;
}

const videoid = this.videoid_ || '';
Copy link
Contributor

Choose a reason for hiding this comment

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

just dev().assert(this.videoid_);, videoid_ should not be null by the time we get here.

width="640"
height="360"
data-autoplay="0">
autoplay>
Copy link
Contributor

Choose a reason for hiding this comment

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

we can't have both noautoplay and autoplay see below for a solution.

* @private
* */
sendCommand_(command, opt_arg) {
this.playerReadyPromise_.then(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

in your case, there is no need to wait for player ready promise

}

if (eventData == 'ready') {
this.element.dispatchCustomEvent(VideoEvents.LOAD);
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, iframe load was also dispatching VideoEvents.LOAD only one is needed. For some players, iframe being loaded is still too early to be considered "ready" that's why they have this custom message. If that the case for you as well? Does this event come from the player at all? Pick between this or iframe load, we only need one.

@@ -83,6 +83,26 @@ Example: Finding the actual width and height
</iframe>
```

##### autoplay
Copy link
Contributor

Choose a reason for hiding this comment

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

as discussed above, we can't do both autoplay and noautoplay

@@ -32,6 +32,10 @@ tags: { # <amp-gfycat>
disallowed_ancestor: "AMP-SIDEBAR"
requires_extension: "amp-gfycat"
attrs: {
name: "autoplay"
Copy link
Contributor

Choose a reason for hiding this comment

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

remove as discussed above.

@honeybadgerdontcare
Copy link
Contributor

validation changes still look good.

@koshka
Copy link
Contributor Author

koshka commented Sep 6, 2017

@aghassemi I made all the changes you requested. Can you please review?
I kept only noautoplay attribute. We want videos to autoplay by default. With noautoplay users can still disable it.
As you suggested I set autoplay attribute if there's no noautoplay. We need it to be able to use play/pause feature of VideoInterface.

/** @override */
createPlaceholderCallback() {
const placeholder = this.win.document.createElement('amp-img');
dev().assert(this.videoid_);
Copy link
Contributor

Choose a reason for hiding this comment

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

for these two lines, pleas do:

const videoId = dev().assertString(this.videoid_);

return this.videoIframeSrc_;
}

const videoid = this.videoid_;
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto: const videoId = dev().assertString(this.videoid_);

if (noautoplay) {
src += '?autoplay=0';
params['autoplay'] = '0';
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, with this PR, AMP completely manages autoplay, I believe you want to set autoplay=0 always now, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aghassemi I fixed video id assert.

About autoplay=0 - yes, AMP manages video autoplay. But an iframe needs this attribute to be 0 only when iframe doesn't autoplay, it uses it for initialization, to set initial state for controls.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also the second build - integration_tests - keeps failing, I'm not sure why. I'm keeping this branch up to date with the latest master.

Copy link
Contributor

Choose a reason for hiding this comment

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

got it, might be worth documenting this reason as code comment
I restarted integration tests, looks like a flake unrelated to your changes.

Copy link
Contributor

@aghassemi aghassemi left a comment

Choose a reason for hiding this comment

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

LGTM, Thanks @koshka!

if (noautoplay) {
src += '?autoplay=0';
params['autoplay'] = '0';
Copy link
Contributor

Choose a reason for hiding this comment

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

got it, might be worth documenting this reason as code comment
I restarted integration tests, looks like a flake unrelated to your changes.

@koshka
Copy link
Contributor Author

koshka commented Sep 11, 2017

@aghassemi cool, thanks. So this change will be in production next week?

@aghassemi
Copy link
Contributor

@koshka, yes, next Wednesday. Thanks implementing the video-interface!

@aghassemi aghassemi merged commit 2c59111 into ampproject:master Sep 11, 2017
@honeybadgerdontcare
Copy link
Contributor

The validator changes are now live in prod.

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.

None yet

4 participants