When using percentage values in width or height inputs, like 100% it breaks the player. This is because the width/height gets also added to the URL as parameters. They are already added as the width/height attributes on the

element so I'd say we can remove those from the URL? Once removed the player works again. I'll put together a patch, unless there are other options?
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

MonsterEyes’s picture

Removing width in the $settings_str in video_embed_field.handlers.inc has worked, the unencode percent from the width seems to be the issue.

carlodimartino’s picture

Sorry to rush you but can you explain this fix? I'm having the same problem with width set to 100%, I'm getting a black frame only. In pixels it's OK. I removed (or thought I did) the width settings in in video_embed_field.handlers.inc but this did not fix it for me. The strange thing is that it all seemed to work fine last week and I don't think I have updated the module since then.

jzavrl’s picture

I think it's also something to do with Google's API. So if you use percentage width/height that gets inputed into the iframe src attribute as parameter. But the "%" breaks the url and so you get a black frame. What I've done is remove the width and height from the settings and set the width and height to the iframe wrapper in CSS like so:

.wrapper {
  position: relative;
  padding-top: 56.25%;
}
iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

The padding-top: 56.25%; is a CSS trick to have a constant 16:9 ratio. And with the above you get a nice responsive video with 100% width and maintaining its aspect ratio.

Perhaps this is something we could add to the module itself? So instead of inputing width and height you would just choose the aspect ratio you would like to have?

carlodimartino’s picture

Great, that worked for me. Thanks! I really only had to use

iframe {
  width: 100%;
}

- leave the width empty and set the height in settings. Videos look fine with correct aspect ratio while playing and the iframe is responsive.

jzavrl’s picture

Yes but if you leave the height in PX value, and set the width in CSS as 100% than on responsive it wont maintain the aspect ratio. The height will stay fixed for the PX value you left. Or am I mistaken?

eyjolfur12’s picture

Fixed this with this change in video_embed_field.handlers.inc line 186:
$settings_str = urlencode (_video_embed_code_get_settings_str($settings));

It is kind of strange that this string was not already urlencoded.

Perignon’s picture

Status: Active » Needs review
FileSize
752 bytes

As @eyjolfur12 said the problem is with the options string not being encoded. I been working on this and came here to create an issue for it and found there already is one! Here is a patch to fix it.

Perignon’s picture

What I didn't look into in the Git history was to see how this was broken. In Beta5 it worked.

Makdomen’s picture

I have fixed this with this change in video_embed_field.handlers.inc line 186:
$settings_str = urlencode (_video_embed_code_get_settings_str($settings));

and the change in CSS

/* Style to make sure the fields are the right way */
.wrapper {
position: relative;
padding-top: 56.25%;
}
iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;

Thanks to eyjolfur12 and jzavrl

Perignon’s picture

Status: Needs review » Reviewed & tested by the community

I am marking this. Well the patch at RTBC. I just deployed this on my production website with over 950 youtube videos embedded in five years of video blogs. It works :-D I did not need CSS changes to fix the problem.

You can see the patch in action here: https://www.swingsurgeon.com/daily-video-tips/

Makdomen’s picture

FileSize
11.88 KB

Now I see that I can`t Hide video annotations when
I have fixed this with this change in video_embed_field.handlers.inc line 186:
$settings_str = urlencode (_video_embed_code_get_settings_str($settings));

But I look around and found the next module
https://www.drupal.org/project/fitvids

I the /sites/all/libraries/ unpack and put the folder.

Go to admin/config/media/fitvids

and in the Custom iframe URLs put

https://www.youtube.com
http://youtu.be
https://vimeo.com/
https://www.kickstarter.com
http://www.dailymotion.com

Return the original Video Embed Field

Go to admin/config/media/vef_video_styles

In the Player Width I have put 710
in the Player Height I have put 400
for youtube and vimeo
For youtube
In the Display annotations
Hide video annotations.

This works perfectly with Width and Height 100%

Vimeo example
http://www.mario.mk/muzika/874
Youtube example (this video have annotations but not in my blog)
http://www.mario.mk/film/1364/captain.america.winter.soldier.2014

trumpetmercenary’s picture

FileSize
393.42 KB
594.58 KB
593.48 KB

I've got my fields set at 100% and the results are "responsive videos" that maintain their ratio when the window is reduced. But how can I make them fill the entire line on all devices?

On laptop: looks great
On wide desktop screen: only fills about half of the page
(see screenshots)

I try making the dimensions 200% or 300% or whatever but this just makes the videos overlap and look really weird with a lot of black space (see screenshot).

Perignon’s picture

Don't hide the patches...

Perignon’s picture

@trumpetmercenary that is beyond the scope of this issue. The issue was the "%" was breaking the player due to it not being URLencoded. Your question is more along the lines of styling and iframes.

jzavrl’s picture

@trumpetmercenary thats a matter of theming. If you have 100% width on the videos that means they expand for the full width of their containers. So the problem is in your containers.

Back on the matter in hand, urlencode() fixes the % in the params. But I still have two questions regarding this...

  1. Is width/height even necessary in the params since they are already in the iframe attributes?
  2. Has anyone replicated Makdomen's problem not being able to hide annotations? Yes, he did provide workaround, but enabling another module (and unnecessary JS), is not really an acceptable sollution.
Makdomen’s picture

Yes I know is unnecessary more JS, but work perfectly on mobile tablets PC with 100% Width and Height.

jzavrl’s picture

That is something that can easily be accomplished with a couple lines of CSS. We need to find a way that the % wont break the URL and that all the features of this module still work.

Perignon’s picture

@jzavrl I have not replicated the problem with the annotations. I can test it today. If it is broke that should be an easy fix because it is part of the URL query string sent for the iframe and I know exactly where that is generated now after 45 minutes of walking code!

My patch fixes the % in the URL. Now is the width and height necessary? That I don't really know. It works with and without it being defined. I am of the mentality, "if it isn't broken, don't fix it". The patch fixed the non-encoded % symbol so the module is back to working the way it was before the upgrade.

tom_howard’s picture

I've had the same issue, it was working a week ago and now the embed is just blank. I had a percentage width on the video style, of which I have removed and left this value blank, instead I have added width: 100%; to the CSS for the iframe. This appears to resolve the issue for the time being.

Perignon’s picture

The patch I uploaded fixes the "%" problem for the module. It was a simple URL encoding issue.

  • plopesc committed 5ad0764 on 7.x-2.x authored by Perignon
    Issue #2537318 by Perignon: Percentage width/height breaks player
    
plopesc’s picture

Status: Reviewed & tested by the community » Fixed

Patch committed to 7.x-2.x
Thank you

kiero63’s picture

I've update to the last release and the pourcent not working well. I'm using the module with colorbox and the height part seems to have a problem. Here some example of link.

No width and no height : vef/load/63712fbb69ae4ce8f330b8a9a1214958&width=&height=5
Width 100% and height 360 : vef/load/63712fbb69ae4ce8f330b8a9a1214958&width=100&height=365

A 5 value is always available.

Thanks

mizi65’s picture

@kiero63: the problem is in video_embed_field.module:563

'height' => $data['height'] + 5,

if $data['height'] have % value

ulic’s picture

url encoding the query string parameters breaks them. See http://codepen.io/ulic/pen/wKzode as an example. The setting that doesn't work in my example is "showinfo" (which hides the title, watch later, and share icons). It seems to me that width and height shouldn't be included in the query string anyway as they are not valid parameters per https://developers.google.com/youtube/player_parameters. I would suggest pulling them out of the settings variable just like what is done with the class setting, so something like:

  // Set these to variables to avoid adding them to URL param string.
  $class = $settings['class'];
  unset($settings['class']);
  $width = $settings['width'];
  unset($settings['width']);
  $height = $settings['height'];
  unset($settings['height']);

  // Construct the embed code.
  $settings['wmode'] = 'opaque';
  $settings_str = _video_embed_code_get_settings_str($settings);

  $output['#markup'] = '<iframe class="' . check_plain($class) . '" width="' . check_plain($width) . '" height="' . check_plain($height) . '" src="//www.youtube.com/embed/' . $id . '?' . $settings_str . '" frameborder="0" allowfullscreen></iframe>';
ulic’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

AdamPS’s picture

FYI

johnjw59@gmail.com’s picture

Sorry to resurrect this after 6 years (maybe I should have created a new issue?), but the same fix needs to be applied to Vimeo embeds. Patch attached.