DemoPlay.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. require('../../vendor/autoload.php');
  3. use Volc\Service\Vod\Models\Request\VodGetPlayInfoRequest;
  4. use Volc\Service\Vod\Models\Response\VodGetPlayInfoResponse;
  5. use Volc\Service\Vod\Vod;
  6. $client = Vod::getInstance();
  7. // $client->setAccessKey("");
  8. // $client->setSecretKey("");
  9. $vid = "your vid";
  10. $expire = 6000000; // 请求的签名有效期
  11. echo "\nstaging 获取播放地址\n";
  12. $req = new VodGetPlayInfoRequest();
  13. $req->setVid($vid);
  14. $req->setSsl('1');
  15. $req->setFormat('hls');
  16. $req->setDefinition('480p');
  17. $req->setFileType('evideo');
  18. $response = new VodGetPlayInfoResponse();
  19. try {
  20. $response = $client->getPlayInfo($req);
  21. } catch (Exception $e) {
  22. echo $e, "\n";
  23. } catch (Throwable $e) {
  24. echo $e, "\n";
  25. }
  26. if ($response->getResponseMetadata()->getError() != null) {
  27. print_r($response->getResponseMetadata()->getError());
  28. }
  29. echo $response->getResult()->getPlayInfoList()[0]->getMainPlayUrl();
  30. echo "\n获取PlayAuthToken\n";
  31. $req2 = new VodGetPlayInfoRequest();
  32. $req2->setVid($vid);
  33. try {
  34. $response2 = $client->getPlayAuthToken($req2, $expire);
  35. echo $response2;
  36. } catch (Exception $e) {
  37. echo $e, "\n";
  38. } catch (Throwable $e) {
  39. echo $e, "\n";
  40. }