Youtube OEmbed 宽度不能大于 740px?

发布于 2024-11-04 06:46:44 字数 1628 浏览 6 评论 0原文

我正在尝试使用 Youtube 的 oEmbed 功能 将视频嵌入到960x580,但由于某种原因,它似乎达到了 740 的最大值。请参见下文:

请求:

http://www.youtube.com/oembed?url=http%3A//www.youtube.com/watch%3Fv%3DbDOYN-6gdRE&format=json&maxwidth=960&maxheight=580

响应:

{
    "provider_url": "http:\/\/www.youtube.com\/",
    "title": "1 of 4 Dr. Bill Lands on Cardiovascular Disease: Omega-6 displaces Omega-3",
    "html": "\u003cobject width=\"740\" height=\"580\"\u003e\u003cparam name=\"movie\" value=\"http:\/\/www.youtube.com\/v\/dgU3cNppzO0?version=3\"\u003e\u003c\/param\u003e\u003cparam name=\"allowFullScreen\" value=\"true\"\u003e\u003c\/param\u003e\u003cparam name=\"allowscriptaccess\" value=\"always\"\u003e\u003c\/param\u003e\u003cembed src=\"http:\/\/www.youtube.com\/v\/dgU3cNppzO0?version=3\" type=\"application\/x-shockwave-flash\" width=\"740\" height=\"580\" allowscriptaccess=\"always\" allowfullscreen=\"true\"\u003e\u003c\/embed\u003e\u003c\/object\u003e",
    "author_name": "LatestNutrition",
    "height": 580,
    "thumbnail_width": 480,
    "width": 740,
    "version": "1.0",
    "author_url": "http:\/\/www.youtube.com\/user\/LatestNutrition",
    "provider_name": "YouTube",
    "thumbnail_url": "http:\/\/i1.ytimg.com\/vi\/dgU3cNppzO0\/hqdefault.jpg",
    "type": "video",
    "thumbnail_height": 360
}

我什至尝试过使用 width 和除了 maxwidthmaxheight 之外,还用 height 参数代替 / ,但我似乎仍然无法让它大于 740。

有吗有什么方法可以解决这个问题,以便我可以获得我需要的尺寸的嵌入式视频?

I'm trying to use Youtube's oEmbed functionality to get a video embed at 960x580, but for some reason it seems to be maxing out at 740. Please see below:

Request:

http://www.youtube.com/oembed?url=http%3A//www.youtube.com/watch%3Fv%3DbDOYN-6gdRE&format=json&maxwidth=960&maxheight=580

Response:

{
    "provider_url": "http:\/\/www.youtube.com\/",
    "title": "1 of 4 Dr. Bill Lands on Cardiovascular Disease: Omega-6 displaces Omega-3",
    "html": "\u003cobject width=\"740\" height=\"580\"\u003e\u003cparam name=\"movie\" value=\"http:\/\/www.youtube.com\/v\/dgU3cNppzO0?version=3\"\u003e\u003c\/param\u003e\u003cparam name=\"allowFullScreen\" value=\"true\"\u003e\u003c\/param\u003e\u003cparam name=\"allowscriptaccess\" value=\"always\"\u003e\u003c\/param\u003e\u003cembed src=\"http:\/\/www.youtube.com\/v\/dgU3cNppzO0?version=3\" type=\"application\/x-shockwave-flash\" width=\"740\" height=\"580\" allowscriptaccess=\"always\" allowfullscreen=\"true\"\u003e\u003c\/embed\u003e\u003c\/object\u003e",
    "author_name": "LatestNutrition",
    "height": 580,
    "thumbnail_width": 480,
    "width": 740,
    "version": "1.0",
    "author_url": "http:\/\/www.youtube.com\/user\/LatestNutrition",
    "provider_name": "YouTube",
    "thumbnail_url": "http:\/\/i1.ytimg.com\/vi\/dgU3cNppzO0\/hqdefault.jpg",
    "type": "video",
    "thumbnail_height": 360
}

I've even tried using width and height parameters in place of / in addition to maxwidth and maxheight, but I still can't seem to get it larger than 740.

Is there any way to get around this so I can get an embedded video at the dimensions I need them at?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

葬心 2024-11-11 06:46:54

我无法在此处粘贴我的代码,

我已使用此代码使用自定义字段在 WordPress 中插入 YouTube 视频...

我需要插入与原始大小不同的视频。在这里您需要定义您的 youtube ID 和所需的宽度

我在末尾添加了一些 youtube 插入选项

http://pastebin.com /KRwvSzqP

I could'nt paste my code here,

I've used this code for inserting youtube videos in wordpress using custom fields...

I needed to insert videos in a different size from the original. here you need to define your youtube ID and desired Width

I've added some youtube insert options at the end

http://pastebin.com/KRwvSzqP

缱绻入梦 2024-11-11 06:46:54

我已经找到了一种解决方法,它并不像我希望的那样漂亮,但它有效:

// Because for some reason Youtube won't allow oEmbed widths greater than 740, so force it to use the proper dimensions
function force_oembed_dimensions($data, $url, $args = array()){
  if (VIDEO_WIDTH > 740)
    $data = preg_replace(array('/ width="\d+"/', '/ height="\d+"/'), array(' width="'.VIDEO_WIDTH.'"', ' height="'.VIDEO_HEIGHT.'"'), $data );
  return $data;
}
add_filter( 'oembed_result', 'force_oembed_dimensions', 10, 3);

但是,如果有人可以提出更优雅的解决方案,我会非常高兴听到它。

I've figured out a workaround, which isn't as pretty as I'd like it to be, but it works:

// Because for some reason Youtube won't allow oEmbed widths greater than 740, so force it to use the proper dimensions
function force_oembed_dimensions($data, $url, $args = array()){
  if (VIDEO_WIDTH > 740)
    $data = preg_replace(array('/ width="\d+"/', '/ height="\d+"/'), array(' width="'.VIDEO_WIDTH.'"', ' height="'.VIDEO_HEIGHT.'"'), $data );
  return $data;
}
add_filter( 'oembed_result', 'force_oembed_dimensions', 10, 3);

However, if anyone can suggest a more elegant solution, I'd be more than happy to hear it.

甜心小果奶 2024-11-11 06:46:54

Embedly 最近添加了一种指定嵌入宽度的方法。它会为您处理缩放问题。只需将 width=960 添加到您的请求中即可。

http://api.embed.ly/1/oembed?width=960&url=http%3A//www.youtube.com/watch%3Fv%3DbDOYN-6gdRE&format=json

Embedly recently added a way to specify the width of the embed. It will take care of the scaling for you. Just add width=960 to your request.

http://api.embed.ly/1/oembed?width=960&url=http%3A//www.youtube.com/watch%3Fv%3DbDOYN-6gdRE&format=json
装纯掩盖桑 2024-11-11 06:46:54

这是一个老问题,但我想无论如何我都会贡献我的发现...

默认情况下,我的 Youtube 文件以 640 宽度嵌入,这比我的 615 内容宽度大。

我将以下内容添加到我的functions.php 文件中:

// Restrict width of Wordpress auto embed objects
add_filter( 'embed_defaults', 'pstv_new_embed_size' );

function pstv_new_embed_size() {
    $embed_size['width'] = 615; // Enter Max width of your content area
    $embed_size['height'] = 500; // Enter Max height for embedded objects
    return $embed_size; // Return new size 
}

起初这仍然不起作用,直到我停用 Jetpack 插件中的嵌入功能。希望这对其他人有帮助。

this is an old question but thought I'd contribute my findings anyway...

By default, my Youtube files were getting embedded at a 640 width which was bigger than my 615 content width.

I added the following to my functions.php file:

// Restrict width of Wordpress auto embed objects
add_filter( 'embed_defaults', 'pstv_new_embed_size' );

function pstv_new_embed_size() {
    $embed_size['width'] = 615; // Enter Max width of your content area
    $embed_size['height'] = 500; // Enter Max height for embedded objects
    return $embed_size; // Return new size 
}

At first this still didn't work, until I deactivated the embed feature in the Jetpack plugin. Hope this helps someone else.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文