I'm working on a site where a user can post a Vimeo video. When a user enters a video url in a form, the video should appear in the Vimeo embedded iframe player.
I would like the user to be able to post the common url, such as
https://vimeo.com/pagefilms/void1
However, it seems as though the Vimeo embedded player requires urls formatted specifically for the player, such as
https://player.vimeo.com/video/204420014
Has anyone had any success with embedding the commonly formatted Vimeo urls into pages?
Here's my code:
<?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
}
?>
You might want to try making an oEmbed request to the custom url to extract the embed code. When making a request to the example you provided:
https://vimeo.com/api/oembed.json?url=https://vimeo.com/pagefilms/void1
You'll get this back:
{
"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 sound\n\nReflectionVOID\nA short film by Lance Page\nOriginal music by Lorn\n\nAfter 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.\n\nIn 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.\n\n\nWatch our behind the scenes documentary for more:\n\n There Will Be Portals: Making of ReflectionVOID\nhttps://vimeo.com/pagefilms/void1bts\n\nA Page Films / Cinematic Syndicate Production\nProduced by Lance Page and Jesse Andrew Clark\nwww.pagefilms.com\nwww.cinematicsyndicate.com\n\nOriginal Music by Lorn\nhttps://lorn.bandcamp.com/\n\nGear and production support:\n\neMotimo\nhttp://emotimo.com\nVizual Jockey\nhttp://www.vizualjockey.com\nRefraction Film Company San Diego\nhttps://www.refractionfilm.com\nAlpine Labs\nhttps://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"
}
This way is preferred because you'll get the entire embed code, as opposed to building the embed code yourself. You can also add arguments to the request to add the preferred height/width of the iframe you want. Documentation for Vimeo's oEmbed response can be found here: