【问题标题】:how to make replace url link of youtube video full screen如何使替换youtube视频的url链接全屏
【发布时间】:2012-01-15 15:10:06
【问题描述】:

我现在正在使用 此代码用于播放 youtube 视频

<?php 
  // Replace Youtube URLs with embed code
   function embedYoutube($text)
   {
     $search = '%          # Match any youtube URL in the wild.
    (?:https?://)?    # Optional scheme. Either http or https
    (?:www\.)?        # Optional www subdomain
    (?:               # Group host alternatives
      youtu\.be/      # Either youtu.be,
    | youtube\.com    # or youtube.com
      (?:             # Group path alternatives
        /embed/       # Either /embed/
      | /v/           # or /v/
      | /watch\?v=    # or /watch\?v=
      )               # End path alternatives.
    )                 # End host alternatives.
    ([\w\-]{10,12})   # Allow 10-12 for 11 char youtube id.
    \b                # Anchor end to word boundary.
    %x';

$replace = '<object width="425" height="344">
    <param name="movie" value="http://www.youtube.com/v/$1?fs=1"</param>
    <param name="allowFullScreen" value="true"></param>
    <param name="allowScriptAccess" value="always"></param>
    <embed src="http://www.youtube.com/v/$1?fs=1"
        type="application/x-shockwave-flash" allowscriptaccess="always" width="425" height="344">
    </embed>
    </object>';

return preg_replace($search, $replace, $text);
}

$string = 'This is the forum post content with some Youtube links:'."\n".
'http://www.youtube.com/watch?v=NLqAF9hrVbY'."\n".
'http://www.youtube.com/v/u1zgFlCw8Aw?fs=1&hl=en_US';

echo embedYoutube($string);

?>

但这些视频无法以全屏模式播放,而且这些嵌入式代码不显示视频的任何信息或拍摄地点。

例如。 http://www.youtube.com/watch?v=YR12Z8f1Dh8 以全屏选项显示视频 带标题 为什么这个 Kolaveri Di 全歌高清宣传视频 youtube.com

和类似的描述 中国惊喜 观看与音乐作曲家 Anirudh、Dhanush、Shruti Hassan、Aishwarya 和音响工程师 Sivakumar 一起录制歌曲的独家视频

像 facebook 一样。

怎么做,谁有答案。

【问题讨论】:

    标签: php html css youtube preg-replace


    【解决方案1】:

    试试,allowFullScreen="true" 在你的 embed 属性中


    要获取description 等其他视频信息,您必须使用 youtube data api, Reference Guide: Data API Protocol

    您可以使用 curl 从服务器端获取信息。

    【讨论】:

    • 一切正常,但是视频的标题和描述呢?
    猜你喜欢
    • 2017-09-14
    • 1970-01-01
    • 2011-10-01
    • 2012-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-11
    • 1970-01-01
    相关资源
    最近更新 更多