【问题标题】:Youtube OEmbed width can't be greater than 740px?Youtube OEmbed 宽度不能大于 740px?
【发布时间】:2011-08-17 04:13:26
【问题描述】:

我正在尝试使用 Youtube's oEmbed functionality 来嵌入 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
}

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

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

【问题讨论】:

    标签: wordpress video youtube embed oembed


    【解决方案1】:

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

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

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

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

    http://pastebin.com/KRwvSzqP

    【讨论】:

      【解决方案2】:

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

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

      但是,如果有人能提出更优雅的解决方案,我将非常乐意听到。

      【讨论】:

        【解决方案3】:

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

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

        【讨论】:

          【解决方案4】:

          这是一个老问题,但我想我还是会贡献我的发现......

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

          【讨论】:

            猜你喜欢
            • 2012-05-08
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2011-08-05
            • 1970-01-01
            • 2016-08-11
            • 2014-12-19
            相关资源
            最近更新 更多