如何检查 Vimeo 视频是否存在?
目前,我有一个基于 vimeo ID 构建 vimeo 播放器的功能
function create_video_player_by_ID($video_id){
$player = '<iframe src="http://player.vimeo.com/video/';
$player .= $video_id.'" ';
$player .= 'width="'.$this->width.'" ';
$player .= 'height="'.$this->height.'" ';
$player .= 'frameborder="0"></iframe>';
return $player;
}
目前,我在播放器窗口中收到一个 vimeo 应用程序,因为 ID 无效,但我想用它做更多事情。如何在视频播放器之前返回布尔值,以便我可以做其他失败的事情?
Currently, I have a function that builds a vimeo player based on a vimeo ID
function create_video_player_by_ID($video_id){
$player = '<iframe src="http://player.vimeo.com/video/';
$player .= $video_id.'" ';
$player .= 'width="'.$this->width.'" ';
$player .= 'height="'.$this->height.'" ';
$player .= 'frameborder="0"></iframe>';
return $player;
}
Currently, I get a vimeo appology in the player window is the ID is invalid, but I would like to do more with that. How can I get a boolean to return before the video player, so I can do something else an failure?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用视频 URL 来使用 HEAD 请求方法。
像这样检查你的 vimeo URL:
希望这对某人有帮助。
You can use the HEAD request method using the video URL.
Check your vimeo URL like so:
Hope this helps someone.
尝试对 src URL 执行 HEAD 请求,以确保它返回状态 200 而不是 404。
您还可以使用视频 API 来获取有关创意的信息。请参阅他们的文档。
Try doing a HEAD request on the src URL to make sure it returns status 200 instead of 404.
You can also use the video API to get information about an idea. See their docs.
出于嵌入目的,最好的方法是使用视频 URL 调用 oEmbed。如果视频无法嵌入,它将返回非 200 代码。
Vimeo oEmbed 文档
For embedding purposes, the best approach would be to make a call to oEmbed with the video url. It will return a non-200 code if the video cannot be embedded.
Vimeo oEmbed docs
在文档中,明确提到了如何从Vimeo获取视频。您需要点击带有视频 ID 的 URL,如果视频退出,则响应代码为 200,否则如果视频不存在,则会给出 404 响应。
参见此处
https://developer.vimeo.com/api/reference/videos#get_video
In the documentation, it clearly mentioned that how can we get a video from Vimeo. You need to hit an URL with video id if the video exit then the response code is 200 otherwise if video does not exist then it will give 404 response.
See here
https://developer.vimeo.com/api/reference/videos#get_video