如何让 Vimeo 链接与嵌入式 iframe 配合使用



我正在开发一个用户可以发布Vimeo视频的网站。当用户在表单中输入视频网址时,该视频应显示在 Vimeo 嵌入式 iframe 播放器中。

我希望用户能够发布通用网址,例如

https://vimeo.com/pagefilms/void1 

但是,Vimeo嵌入式播放器似乎需要专门为播放器格式化的URL,例如

https://player.vimeo.com/video/204420014

有没有人成功地将通常格式化的Vimeo网址嵌入到页面中?

这是我的代码:

<?php 
if(isset($video2)){
    echo '<h3>Video 2</h3>'
?>
    <p class="video text-center">
<?php
        echo '<iframe src="' . $video2 . '" width="640" height="360"
        frameborder="0" webkitallowfullscreen mozallowfullscreen
        allowfullscreen></iframe>'; 
?>
    </p>
<?php
}   
?>

您可能需要尝试向自定义 URL 发出 oEmbed 请求以提取嵌入代码。向您提供的示例发出请求时:

https://vimeo.com/api/oembed.json?url=https://vimeo.com/pagefilms/void1

你会得到这个:

{
  "type": "video",
  "version": "1.0",
  "provider_name": "Vimeo",
  "provider_url": "https://vimeo.com/",
  "title": "ReflectionVOID",
  "author_name": "Page Films",
  "author_url": "https://vimeo.com/pagefilms",
  "is_plus": "1",
  "html": "<iframe src="https://player.vimeo.com/video/204420014" width="640" height="272" frameborder="0" title="ReflectionVOID" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>",
  "width": 640,
  "height": 272,
  "duration": 345,
  "description": "*Recommended: dark viewing environment / 4K or HD resolution / quality soundnnReflectionVOIDnA short film by Lance PagenOriginal music by LornnnAfter dusk in the high desert, as the sky quickly darkens, a lone hiker stumbles across a window into another world. As the man approaches the portal, he is met with his own reflection and we suddenly sink into the ReflectionVOID.nnIn the VOID, scattered portals reflect star patterns against deep black skies. The stars sing to us, but the relentless nature of the high desert reminds us of our mortality. The razor sharp cactus blades and the cold jagged rock formations threaten our fragile bodies. The portals allow us a deeper perspective, they show us the Universe as we reach into our souls for cosmic significance. As we sink deeper into the unknown, we’re met with a tall human-like figure, a mysterious desert dweller with a purpose and a message.nnnWatch our behind the scenes documentary for more:nn There Will Be Portals: Making of ReflectionVOIDnhttps://vimeo.com/pagefilms/void1btsnnA Page Films / Cinematic Syndicate ProductionnProduced by Lance Page and Jesse Andrew Clarknwww.pagefilms.comnwww.cinematicsyndicate.comnnOriginal Music by Lornnhttps://lorn.bandcamp.com/nnGear and production support:nneMotimonhttp://emotimo.comnVizual Jockeynhttp://www.vizualjockey.comnRefraction Film Company San Diegonhttps://www.refractionfilm.comnAlpine Labsnhttps://alpinelaboratories.com",
  "thumbnail_url": "https://i.vimeocdn.com/video/621081707_640.jpg",
  "thumbnail_width": 640,
  "thumbnail_height": 272,
  "thumbnail_url_with_play_button": "https://i.vimeocdn.com/filter/overlay?src0=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F621081707_640.jpg&src1=http%3A%2F%2Ff.vimeocdn.com%2Fp%2Fimages%2Fcrawler_play.png",
  "upload_date": "2017-02-16 15:03:43",
  "video_id": 204420014,
  "uri": "/videos/204420014"
}

这种方式是首选,因为您将获得整个嵌入代码,而不是自己构建嵌入代码。您还可以向请求添加参数,以添加所需 iframe 的首选高度/宽度。Vimeo 的 oEmbed 响应的文档可以在这里找到:

https://developer.vimeo.com/apis/oembed

最新更新