Allow oEmbed video iFrames to expand to available space

Created on 24 March 2023, over 1 year ago
Updated 8 March 2024, 4 months ago

Problem/Motivation

When adding an oembed remote video with the media module, the resulting video always displays at width 200px height 113px.
This is unlikely to be the desired outcome.

It is likely that most people will expect the video to display at the smaller of 100% width (of the content area) or the original width of the media in px, and maintain the original correct aspect ratio.

🐛 Some oEmbed videos do not maintain aspect ratio Needs work has some examples of alternate .css in comment 27 and 62 to address the issue.

However this suffers from an assumption as to the desired ratio of the source video.

Steps to reproduce

This can be seen on any clean install of Drupal 10.x

1. Install Drupal
2. Enable the media module.
3. Insert a media field into the basic page content type
4. Create a content item with a remote oembed youtube video

It can be observed here:
https://tugboat10-radtonmrxxuykt76b3oveqdu9pp4zqwg.tugboatqa.com/node/59

Proposed resolution

Two potential solutions:

  1. Alter the attributes of the iframe & its parent in PHP to add inline styles
  2. Add JavaScript that adds inline styles to set the aspect ratio of the iFrame's parent
Feature request
Status

Postponed: needs info

Version

11.0 🔥

Component
Media 

Last updated about 14 hours ago

Created by

🇬🇧United Kingdom martin@manarock.co.uk

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Issue created by @martin@manarock.co.uk
  • 🇺🇸United States andy-blum Ohio, USA
  • Status changed to Needs review about 1 year ago
  • 🇮🇳India Gauravvv Delhi, India

    As all the modern browsers supports the aspect-ratio property. I have used the same and fixes the issue. please review

  • 🇬🇧United Kingdom martin@manarock.co.uk

    This will work for a 16/9 video - do we want to (or should we?) try to solve for other use cases? I don't know if there is a standard approach to a core theme, but either:

    1 - We could add classes that allow for common video ratios, probably something like:

    16:9 (Widescreen) 16:9
    9:16 (Vertical) ...
    1:1 (Square) ...
    4:3 (Fullscreen) ...
    21:9 (Cinematic Widescreen)

    2 - We could look to calculate the ratio? I am aware of https://github.com/davatron5000/FitVids.js as jquery solution, and am also aware that jquery is no longer native in 9.x onwards. Is there a javascript approach in core that would help?

    Of course these points are moot if its ok for the theme to be opinionated about 16/9 ratios being expected!

  • Status changed to Needs work about 1 year ago
  • 🇺🇸United States andy-blum Ohio, USA

    As mentioned in #4, this is a very rigid solution, but I don't think adding more, different rigid solutions is the answer. Instead, we probably want to access the iframe's set width/height. Those attributes are set here, but I'm not really sure how we would best make use of them. I'll reach out to the media maintainers to see if they have any input.

  • Status changed to Needs review about 1 year ago
  • 🇺🇸United States andy-blum Ohio, USA

    New patch attached with new approach that should be more flexible.

  • 🇪🇸Spain marcoscano Barcelona, Spain

    Yes, media using oEmbed in core isn't fully responsible and there are issues in certain scenarios dealing with dimensions (or lack of) that come from the providers. For example:

    🐛 Some oEmbed videos do not maintain aspect ratio Needs work
    🐛 oEmbed videos are not fully responsive Needs work
    Negotiate max width/height of oEmbed assets more intelligently Needs work

    each focusing on one aspect of the same problem, IMO.

    So ultimately, I believe this should be solved by the core media module in a generic way for all providers. Having that said, if in the meantime Olivero has a way to workaround it in a generic and simple way, maybe that's reasonable, and also serves as example of how sites can do it in their themes? We could leave a @todo in the workaround to remove it when the iframe is made fully responsible by the core module?

    Also a little suggestion on the latest patch:

    +++ b/core/themes/olivero/olivero.theme
    @@ -359,6 +359,19 @@ function olivero_preprocess_radios(&$variables) {
    +  if ($variables['entity_type'] === 'media' && $variables['field_name'] === 'field_media_oembed_video') {
    

    This field can be named anything really. It would be great if we could target this in a more generic way. How about something like this instead?

      if (!empty($variables['element']['#object']) &&
        ($variables['element']['#object'] instanceof \Drupal\media\MediaInterface) &&
        ($variables['element']['#object']->getSource() instanceof \Drupal\media\Plugin\media\Source\OEmbedInterface)) {
        ...
      }
    
  • Status changed to Needs work about 1 year ago
  • 🇺🇸United States andy-blum Ohio, USA
  • Status changed to Needs review about 1 year ago
  • 🇺🇸United States andy-blum Ohio, USA

    Thanks for the feedback, Marcos!

    Moved to a MR because I hate making interdiffs.

  • @andy-blum opened merge request.
  • Status changed to Needs work about 1 year ago
  • 🇺🇸United States smustgrave

    Surprised the bot hasn't got this. But build failure in MR.

    Also FWIW I'm reviewing Negotiate max width/height of oEmbed assets more intelligently Needs work right now too.

  • First commit to issue fork.
  • 🇺🇾Uruguay rpayanm

    Trying to fix the CC Failed and improved one line of code.

  • Status changed to Needs review about 1 year ago
  • 🇺🇾Uruguay rpayanm

    Please review.

  • Status changed to Needs work about 1 year ago
  • 🇺🇸United States smustgrave

    Added 1 comment to MR.

  • First commit to issue fork.
  • Status changed to Postponed: needs info 4 months ago
  • 🇺🇸United States smustgrave

    Can anyone confirm Negotiate max width/height of oEmbed assets more intelligently Needs work solve the problem.

Production build 0.69.0 2024