amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

Custom poster for video is not fitting appropriately

Open sagarnasit opened this issue 6 years ago • 4 comments

What's the issue?

Custom poster used in amp-video not fitting appropriately if the aspect ratio of poster and video are different.

How do we reproduce the issue?

Here is the codepen link.

  1. Add the amp-video component.
  2. Add poster image with different aspect ratio.

What browsers are affected?

All browsers.

Which AMP version is affected?

Powered by AMP ⚡ HTML – Version 2005050322002

sagarnasit avatar May 13 '20 16:05 sagarnasit

Comparing the non-AMP and AMP version as generated by the AMP plugin, I do see a difference:

image

The reason for why the non-AMP version has a poster image that is covering rather than containing the element is that in the non-AMP version WordPress is using the MediaElement.js library which puts the poster image in an element that overlays the video, and the poster image is set as the background image of that element and is given background-size: cover:

image

However, amp-video is not doing this. It is using the browser's built-in poster image for the video element. That poster image can't be directly styled, however, as it is not in the DOM. (Perhaps shadow DOM?)

One workaround would be to not use the poster attribute but rather to use an amp-img as a placeholder. This kinda works, but it results in the “poster” only being shown until the video is loaded and then the first frame of the video is shown. See example: https://codepen.io/westonruter/pen/qBOyMEZ

The only way I can see that this can be emulated is if the video element initially gets object-fit:cover (as proposed in https://github.com/ampproject/amp-wp/pull/4695) but then remove it once the video starts playing. This can't be done in AMP at present, however, because the firstPlay event on amp-video is low-trust, so we'd not be able to fire an animation and not do an action like toggling a class.

cc @wassgha

westonruter avatar May 13 '20 17:05 westonruter

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Nov 06 '21 04:11 stale[bot]

Hello👋 I have added PR #36845 which should fix the custom poster fit issue for the amp-video 1.0 version. The PR adds by default object-fit set as cover and updates it to object-fit: contain after the video is played to avoid video being displayed cropped because of cover property CC: @adamsilverstein

deepaklalwani97 avatar Nov 10 '21 12:11 deepaklalwani97

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Nov 13 '22 03:11 stale[bot]