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
}

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

有什么办法可以解决这个问题,这样我就可以获得所需尺寸的嵌入式视频?

4

4 回答 4

2

我不能在这里粘贴我的代码,

我已经使用此代码使用自定义字段在 wordpress 中插入 youtube 视频...

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

我在最后添加了一些 youtube 插入选项

http://pastebin.com/KRwvSzqP

于 2011-07-29T05:41:21.823 回答
1

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

http://api.embed.ly/1/oembed?width=960&url=http%3A//www.youtube.com/watch%3Fv%3DbDOYN-6gdRE&format=json
于 2011-05-02T20:43:11.013 回答
1

我想出了一个解决方法,它不像我想要的那么漂亮,但它有效:

// 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);

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

于 2011-05-02T19:12:00.507 回答
0

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

默认情况下,我的 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 插件中的嵌入功能。希望这对其他人有帮助。

于 2013-09-03T12:13:03.383 回答