📜  获取嵌入 vimeo 视频长度 - 无论代码示例

📅  最后修改于: 2022-03-11 14:55:08.478000             🧑  作者: Mango

代码示例1
/**
* Vimeo video duration in seconds
*
* @param $video_url
* @return integer|null Duration in seconds or null on error
*/
public static function vimeoVideoDuration($url) {

  $json_url = 'https://vimeo.com/api/oembed.json?url=' . $url;

  $ch = curl_init($json_url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  $data = curl_exec($ch);
  curl_close($ch);
  try{
    $data = json_decode($data, true);
  }catch (\Exception $e){ $data = null; }

  if (!isset($data["duration"])) {
    return null;
  }

  // in seconds
  return $data["duration"];
}