全部产品
存储与CDN 数据库 安全 应用服务 数加·人工智能 数加·大数据基础服务 互联网中间件 视频服务 开发者工具 解决方案 物联网
媒体转码

查询媒体-使用OSS文件地址

更新时间:2017-07-13 11:56:10

用户在不知道媒体ID的情况下(直播走工作流转点播),可以通过媒体的输入地址进行媒体信息的查询,接口为 QueryMediaListByURL

  1. package com.aliyun.mts.api.demo
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.aliyuncs.DefaultAcsClient;
  4. import com.aliyuncs.exceptions.ClientException;
  5. import com.aliyuncs.mts.model.v20140618.QueryMediaListByURLRequest;
  6. import com.aliyuncs.mts.model.v20140618.QueryMediaListByURLResponse;
  7. import com.aliyuncs.profile.DefaultProfile;
  8. import java.io.UnsupportedEncodingException;
  9. import java.net.URLEncoder;
  10. public class QueryMediaListByURLDemo {
  11. private DefaultAcsClient client = null;
  12. private final String REGION = "<region>";
  13. private final String ID="<accessKeyId>";
  14. private final String KEY ="<accessKeySecret>";
  15. public QueryMediaListByURLDemo() throws ClientException {
  16. this.client = new DefaultAcsClient(DefaultProfile.getProfile(REGION, ID, KEY));
  17. }
  18. //根据视频源OSS地址查询媒体信息, 如: 媒体ID, 媒体状态及其他属性
  19. private void queryMediaListByURL() throws ClientException, UnsupportedEncodingException {
  20. QueryMediaListByURLRequest request = new QueryMediaListByURLRequest();
  21. String ossHost = 'http://<input-bucket>.<region>.aliyuncs.com/';
  22. String ossObject = "test/笑傲江湖.mp4";
  23. //ossObject需要符合rfc3986标准
  24. String rfc3986Object = encodeByRFC3986(ossObject);
  25. request.setFileURLs(ossHost + rfc3986Object);
  26. QueryMediaListByURLResponse response = this.client.getAcsResponse(request);
  27. System.out.println(JSONObject.toJSONString(response.getMediaList()));
  28. }
  29. private String encodeByRFC3986(String object) throws UnsupportedEncodingException {
  30. StringBuilder builder = new StringBuilder();
  31. String[] segments = object.split("/");
  32. for (int i = 0; i < segments.length; i++) {
  33. builder.append(percentEncode(segments[i]));
  34. if (i != segments.length - 1) {
  35. builder.append("/");
  36. }
  37. }
  38. return builder.toString();
  39. }
  40. private static String percentEncode(String value) throws UnsupportedEncodingException {
  41. if (value == null)
  42. return null;
  43. return URLEncoder.encode(value, "UTF-8").replace("+", "%20").replace("*", "%2A").replace("%7E", "~");
  44. }
  45. public static void main(String[] args) {
  46. try {
  47. QueryMediaListByURLDemo demo = new QueryMediaListByURLDemo();
  48. demo.queryMediaListByURL();
  49. } catch (Exception e) {
  50. e.printStackTrace();
  51. }
  52. }
  53. }
本文导读目录