

Is it possible to change the size manually?
TABLENAME_dml.php
file the template-placeholder <%%YOUTUBE(FIELDNAME)%%>
gets replaced, calling the function get_embed
. Here we still have the correct size-settings, given in field-configuration. The placeholder gets replaced by the return value of get_embed('youtube', $urow['video'], '480', '360')
. I've just tested that function call. It returns a complete <iframe .../>
-tag including width/height dimensions. Those dimensions do NOT match with our given configuration:
To me, it looks like YouTube automatically returns these dimensions no matter what we pass. But honestly, I don't know much about it. So I manually ran the request that AppGini makes to YouTube:Code: Select all
https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=JRbHMSrK-bw&ab_channel=DreamTheater&maxwidth=480&maxheight=360
<iframe>
HTML code afterwards? Code: Select all
<!-- file: hooks/footer-extras.php -->
<pre>
<?php
$urow = getRecord("instructions", 1);
$url = $urow["video"];
$provider = "youtube";
$providers = [
'youtube' => ['oembed' => 'https://www.youtube.com/oembed?'],
];
$max_width = 480;
$max_height = 360;
$oembed = $providers[$provider]['oembed'] . 'url=' . urlencode($url) . "&maxwidth={$max_width}&maxheight={$max_height}&format=json";
$data_json = request_cache($oembed, true);
var_dump($data_json);
?>
</pre>
Code: Select all
string(823) "{"title":"Dream Theater - Metropolis Pt.2 Encore (from Breaking The Fourth Wall)","author_name":"Dream Theater","author_url":"https://www.youtube.com/@dreamtheaterofficial","type":"video","height":113,"width":200,"version":"1.0","provider_name":"YouTube","provider_url":"https://www.youtube.com/","thumbnail_height":360,"thumbnail_width":480,"thumbnail_url":"https://i.ytimg.com/vi/JRbHMSrK-bw/hqdefault.jpg","html":"\u003ciframe width=\u0022200\u0022 height=\u0022113\u0022 src=\u0022https://www.youtube.com/embed/JRbHMSrK-bw?feature=oembed\u0022 frameborder=\u00220\u0022 allow=\u0022accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\u0022 allowfullscreen title=\u0022Dream Theater - Metropolis Pt.2 Encore (from Breaking The Fourth Wall)\u0022\u003e\u003c/iframe\u003e"}"
Code: Select all
... "height":113,"width":200...
<iframe>
-dimensions.[code]...[/code]
blocks for better readabilityhooks/TABLENAME-dv.js
file or in any common file being loaded in your DV:Code: Select all
function resizeYouTubeVideo(tablename, fieldname, width, height) {
const iframe = jQuery(`[data-table='${tablename}'] label[for='${fieldname}']`).parent().find(`div > iframe[src^='https://www.youtube.com/embed']`);
if (iframe.length == 1) {
const parent = iframe.parent();
parent.css("overflow","auto");
const size = {
width: iframe.attr("width"),
height: iframe.attr("height")
};
size.ratio = size.width / size.height;
if (size.width > size.height) {
iframe.attr("width", width);
iframe.attr("height", width / size.ratio);
}
}
}
hooks/TABLENAME-dv.js
:TABLENAME
, FIELDNAME
, WIDTH
, HEIGHT
. Change those according to your needs.Code: Select all
resizeYouTubeVideo("instructions", "video", 800, 600);
[code]...[/code]
blocks for better readability