- Issue created by @hanneshh
- πͺπͺEstonia hanneshh
What do you mean by that cilefen? ("This may be more of a feature request than a bug.")
I am not asking for new features - I am asking not to break the remote video's url when handling it.
There is a lot of functionality that gets broken because of how Drupal's media module handles video urls.
For example youtube has GET variables you can add to the end of the video url when embedding a video, that control various aspects from autoplay and mute to the related videos that get shown. The current way of handling media remote video urls (1. take youtube video ID 2. remove everything else) breaks all of that functionality.
Again, I am not asking for new functionality, I am just asking not to completely annihilate the url when handling it.
- π¦πΊAustralia larowlan π¦πΊπ.au GMT+10
Autoplay and mute can be configured from the formatter in the manage display screen
- π¦πΊAustralia larowlan π¦πΊπ.au GMT+10
Hmm looks like that formatter is provided by a module other than core.
- π¦πΊAustralia larowlan π¦πΊπ.au GMT+10
Yes I'm thinking of video_embed_field.
It should be possible to add a custom formatter for Oembed in core though.
- πͺπͺEstonia hanneshh
Does YouTube support those parameters with oembed?
Yes, of course YouTube supports those parameters with oembed :)
I've made a temporary js fix that solves the problem, but isn't the "right" way of doing things:
function fixAutoplay() { jQuery('iframe[src^="/et/media/oembed?"]').each(function () { if (jQuery(this).attr('src').indexOf('autoplay%3D1') == -1) return; var nestedIframes = jQuery(this).contents().find('iframe'); if (nestedIframes.length > 0) { nestedIframes.each(function () { var src = jQuery(this).attr('src'); if (src) { src += (src.indexOf('?') === -1 ? '?' : '&') + 'autoplay=1&mute=1'; jQuery(this).attr('src', src); } }); } }); }
The right way of doing things would be to just modify the code that strips the url of all other variables besides the video ID, would it not? :)
- πͺπͺEstonia hanneshh
Larowlan, why did you change the category to feature request instead of a bug?
The infromation user outputted (youtube embed url) gets removed by accident that shouldn't be removed. This is a bug, plain and simple. I do not want to use video_embed_field - I am talking about using Media.
video_embed_field even has a disclaimer:
If you are installing this module for integration with a media library, core already contains all the tools required for embedding remotely hosted videos. This module should no longer be required for most use cases and should be avoided if possible.
- π¦πΊAustralia larowlan π¦πΊπ.au GMT+10
Looking at the code path in
\Drupal\media\OEmbed\UrlResolver::getResourceUrl
This ends up in
\Drupal\media\OEmbed\Endpoint::buildResourceUrl
This ends up calling the endpoint with the Url passed and the oembed resource returns the markup for the iframe.
For example for youtube, it ends up at a URL like so https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=IBAFP...
If you visit that URL you can see in the response that Youtube returns the stripped version.
In fact, Drupal still stores the originally submitted url
\Drupal\media\Entity\Media::load(5026)->toArray()['field_media_oembed_video'] = [ [ "value" => "https://www.youtube.com/watch?v=IBAFPFo2F0U&autoplay=1", ], ]
You can also see from
\Drupal\media\Controller\OEmbedIframeController::render
that we simply return the html from the oembed provider. So that's what Youtube is giving us in the URL above.So in summary, this issue is caused by how YouTube implements Oembed.
If you wish to do things differently, you can use a different formatter. You have access to the original URL still.
This is either a feature request to add a formatter that ignores what the oembed provider provides for 'html' or works as designed.
My opinion is that its the later, we can't special case a formatter for Youtube in a generic oembed field. People can write custom code to create a formatter or contrib project for that if they wish.
- Status changed to Closed: works as designed
about 1 year ago 10:53pm 7 February 2024 - π¦πΊAustralia larowlan π¦πΊπ.au GMT+10
Oh I missed your comment in #10, you found the same thing as me - but I still don't think we should be doing anything with the HTML from the oembed response in core. Especially not special-casing Youtube. That belongs in contrib or custom code.
On that basis, marking this one.
- π¦π²Armenia le72 Yerevan π¦π²
Thank you for the post.
I am facing the same issue. So, what is the best approach to have muted (or looped) YouTube media videos embedded?
Maybe a module with a field formatter supporting YouTube and Vimeo videos? - π¨π¦Canada RobLoach Earth
We ran into something similar on the Vimeo URLs. The options that you pass in as URL parameters are stripped when creating the iFrame for the oembed.
- Status changed to Needs work
about 1 month ago 11:36pm 5 February 2025 - π³πΏNew Zealand quietone
10.3.x is in security mode and Drupal 10 itself is now in maintenance mode, so this is not eligible for Drupal 10.