Skip to content

✨amp-ima-video: Show Controls on Hover#20130

Merged
torch2424 merged 5 commits intoampproject:masterfrom
torch2424:amp-ima-video-hover-controls
Jan 9, 2019
Merged

✨amp-ima-video: Show Controls on Hover#20130
torch2424 merged 5 commits intoampproject:masterfrom
torch2424:amp-ima-video-hover-controls

Conversation

@torch2424
Copy link
Copy Markdown
Contributor

relates to #19393

This enables showing ima-video controls on hover, instead of onclick. This also makes sure to work on mobile devices to preserve the tap to show controls behavior, as it is in amp-video.

From a UX perspective, got an approval by @spacedino to make amp-ima-video to match the behavior of amp-video as much as possible, and this PR falls inline with that 😄.

cc @curseagain

Example

Desktop

imavideohover

Mobile

imavideomobile

Copy link
Copy Markdown
Contributor

@zhouyx zhouyx left a comment

Choose a reason for hiding this comment

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

Thanks for the new feature! Looks cool. LGTM with one nit and one question.

// Something blocked ima3.js from loading - ignore all IMA stuff and just play
// content.
videoPlayer.addEventListener(interactEvent, showControls);
addHoverEventToElement(/** @type !Element*/(videoPlayer), showControls);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: extra space after */

}

// Hide controls after 3 seconds
if (playerState == PlayerStates.PLAYING) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I was playing with the mousemove event, and it seems that it fires a LOT. I am not sure about the cost of setTimeout and clearTimeout. Do you think it's fine w/o a throttle?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah the mousemove event does fire a lot, but I was thinking about it and I essentially came to two conclusions:

  1. The event will only be fired on desktop devices, during certain sections of watching the video.
  2. Adding a throttle may improve user experience, however, I couldn't think of a good way to implement this that would be flexible and testable, thus hurting developer experience.

Though, I do think this is worth having a quick chat about on how we can easily add/remove this dynamic event, that has a throttle. 😄 I'll reach out tommorow, or vice/versa 👍

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Plus one for throttling - if possible - though controlsVisible is clear and succinct!

imaVideoObj.showControls
);
videoPlayerElement.dispatchEvent(clickEvent);

This comment was marked as resolved.

}

// Hide controls after 3 seconds
if (playerState == PlayerStates.PLAYING) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Plus one for throttling - if possible - though controlsVisible is clear and succinct!

}

/**
* Removess the appropriate event listener from an element

This comment was marked as resolved.


/**
* Adds the appropriate event listener to an element
* to represent a hover state. And adds an appropriate

This comment was marked as resolved.

@torch2424
Copy link
Copy Markdown
Contributor Author

@zhouyx @curseagain made all requested changes! Added a throttler as well 😄

Copy link
Copy Markdown
Member

@curseagain curseagain left a comment

Choose a reason for hiding this comment

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

LGTM. Great tests!

* since this is applied per element,
* and would require wrapping the callback.
* Thus, the callback passed should be,
* appropriately throttled. See showControlsThrottled.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great commenting!! ❤️

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks! 😄

@torch2424
Copy link
Copy Markdown
Contributor Author

@zhouyx This is good to go! Fixed the rate-limit build system thing 😄

Copy link
Copy Markdown
Contributor

@zhouyx zhouyx left a comment

Choose a reason for hiding this comment

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

Sorry for the late response here. LGTM. Thank you for the feature!!!

@torch2424
Copy link
Copy Markdown
Contributor Author

@zhouyx No worries! Thank you!

@torch2424 torch2424 merged commit 4e6291a into ampproject:master Jan 9, 2019
@torch2424 torch2424 deleted the amp-ima-video-hover-controls branch January 9, 2019 20:40
noranazmy pushed a commit to noranazmy/amphtml that referenced this pull request Mar 22, 2019
* Need to fix check-types and make PR

* Fixed check types

* Fixed most pr comments

* FInished all changes

* Fixed the rate limit ads thing
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.

4 participants