gpt4 book ai didi

php - 如何获得vimeo视频的长度?

转载 作者:行者123 更新时间:2023-12-05 00:29:08 25 4
gpt4 key购买 nike

我有一个大问题。问题是如何获得vimeo视频的持续时间?这是场景。

I have a input field in this field say i enter youtube url now i want to put a validation that video should only be of 1 min, if yes then i store this in database else i show an error message.



vimeo视频文件可以这样做吗?

最佳答案

用法

echo vimeoVideoDuration('https://vimeo.com/115134273');
// output: 63 (video duration in seconds)

函数
/**
* Vimeo video duration in seconds
*
* @param $video_url
* @return integer|null Duration in seconds or null on error
*/
function vimeoVideoDuration($video_url) {

$video_id = (int)substr(parse_url($video_url, PHP_URL_PATH), 1);

$json_url = 'http://vimeo.com/api/v2/video/' . $video_id . '.xml';

$ch = curl_init($json_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);
$data = new SimpleXmlElement($data, LIBXML_NOCDATA);

if (!isset($data->video->duration)) {
return null;
}

$duration = $data->video->duration;

return $duration; // in seconds
}

关于php - 如何获得vimeo视频的长度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7772825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com