edit-icon download-icon

Query media - Use OSS file address

Last Updated: Jan 02, 2018

If you do not know the media ID (a live video converted to an on-demand video using the media workflow), you can use the media input URL to query the media information over QueryMediaListByURL.

  1. <?php
  2. include_once 'aliyun-php-sdk-core/Config.php';
  3. use Mts\Request\V20140618 as Mts;
  4. date_default_timezone_set('PRC');
  5. class QueryMediaListByURLDemo {
  6. private $client;
  7. private $region = '<region>';
  8. private $accessKeyId = '<accessKeyId>';
  9. private $accessKeySecret = '<accessKeySecret>';
  10. function __construct()
  11. {
  12. $profile = DefaultProfile::getProfile($this->region, $this->accessKeyId, $this->accessKeySecret);
  13. $this->client = new DefaultAcsClient($profile);
  14. }
  15. function queryMediaListByUrl()
  16. {
  17. $request = new Mts\QueryMediaListByURLRequest();
  18. $ossDomain = 'http://<input-bucket>.<region>.aliyuncs.com/';
  19. #ossObject must be RFC3986-encoded.
  20. $ossObject = $this->encodeByRFC3986('test/The Legend of the Swordsman.mp4');
  21. $request->setFileURLs($ossDomain.$ossObject);
  22. $response = $this->client->getAcsResponse($request);
  23. echo json_encode($response);
  24. }
  25. function encodeByRFC3986($arg_1)
  26. {
  27. $encodeOssObject="";
  28. $arraylist = explode("/", $arg_1);
  29. for($i = 0; $i < count($arraylist); $i++)
  30. {
  31. $tmp = rawurlencode($arraylist[$i]);
  32. $encodeOssObject = $encodeOssObject.$tmp;
  33. if ($i !== count($arraylist) -1) {
  34. $encodeOssObject = $encodeOssObject."/";
  35. }
  36. }
  37. return $encodeOssObject;
  38. }
  39. }
  40. $demo = new QueryMediaListByURLDemo();
  41. $demo->queryMediaListByUrl();
  42. ?>
Thank you! We've received your feedback.