全部产品
云市场

音视频播放

更新时间:2019-06-17 11:54:53

初始化客户端

使用前请先初始化客户端,请参考initVodClient接口

获取播放地址

接口参数和返回字段,请参考 GetPlayInfo

  1. function getPlayInfo($client, $videoId) {
  2. $request = new vod\GetPlayInfoRequest();
  3. $request->setVideoId($videoId);
  4. $request->setAuthTimeout(3600*24);
  5. $request->setAcceptFormat('JSON');
  6. return $client->getAcsResponse($request);
  7. }
  8. // 注意捕获异常
  9. try {
  10. $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');
  11. $playInfo = getPlayInfo($client, 'videoId');
  12. print_r($playInfo->PlayInfoList->PlayInfo);
  13. var_dump($playInfo);
  14. } catch (Exception $e) {
  15. print $e->getMessage()."\n";
  16. }

获取播放凭证

接口参数和返回字段,请参考 GetVideoPlayAuth

  1. function getPlayAuth($client, $videoId) {
  2. $request = new vod\GetVideoPlayAuthRequest();
  3. $request->setVideoId($videoId);
  4. $request->setAuthInfoTimeout(3000);
  5. $request->setAcceptFormat('JSON');
  6. $response = $client->getAcsResponse($request);
  7. return $response;
  8. }
  9. try {
  10. $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');
  11. $playAuth = getPlayAuth($client, 'videoId');
  12. print($playAuth->PlayAuth."\n");
  13. print_r($playAuth->VideoMeta);
  14. } catch (Exception $e) {
  15. print $e->getMessage()."\n";
  16. }