通过阅读本文,您可以了解通过服务端SDK调用OpenAPI管理智能媒体服务内容库的示例代码。
使用说明
目前支持通过OSS文件或VOD媒资ID注册媒资内容。
示例代码
您可以通过阿里云OpenAPI开发者门户在线调试。
package com.aliyun.ice.sample;
import com.aliyun.ice20201109.Client;
import com.aliyun.ice20201109.models.*;
import com.aliyun.teaopenapi.models.Config;
public class MediaInfoSample {
public static void main (String[] args) throws Exception{
// 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
// 本示例以将AccessKey ID和 AccessKey Secret保存在环境变量为例说明。
com.aliyun.credentials.Client credentialClient = new com.aliyun.credentials.Client();
Config config = new Config();
config.setCredential(credentialClient);
// 如需硬编码AccessKey ID和AccessKey Secret,代码如下,但强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
// config.accessKeyId = <yourAccessKeyId>;
// config.accessKeySecret = <yourAccessKeySecret>;
config.endpoint = "ice.cn-shanghai.aliyuncs.com";
Client client = new Client(config);
// 注册媒资内容
RegisterMediaInfoRequest registerMediaInfoRequest = new RegisterMediaInfoRequest();
registerMediaInfoRequest.setInputURL("oss://test.sample.com/media/cover/mediaid.jpg");
registerMediaInfoRequest.setMediaType("video");
RegisterMediaInfoResponse registerMediaInfoResponse = client.registerMediaInfo(registerMediaInfoRequest);
String mediaId = registerMediaInfoResponse.getBody().getMediaId();
System.out.println("mediaId : " + mediaId);
// 获取单个内容
GetMediaInfoRequest getMediaInfoRequest = new GetMediaInfoRequest();
getMediaInfoRequest.setMediaId(mediaId);
GetMediaInfoResponse getMediaInfoResponse = client.getMediaInfo(getMediaInfoRequest);
System.out.println("mediaId : " + getMediaInfoResponse.getBody().getMediaInfo().getMediaId());
// 修改内容信息
UpdateMediaInfoRequest updateMediaInfoRequest = new UpdateMediaInfoRequest();
updateMediaInfoRequest.setMediaId(mediaId);
updateMediaInfoRequest.setCoverURL("http://test.oss-cn-shanghai.aliyuncs.com/media/cover/mediaid.jpg");
client.updateMediaInfo(updateMediaInfoRequest);
// 删除内容信息
DeleteMediaInfosRequest deleteMediaInfosRequest = new DeleteMediaInfosRequest();
deleteMediaInfosRequest.setMediaIds(mediaId);
client.deleteMediaInfos(deleteMediaInfosRequest);
// 列出符合条件的媒资
ListMediaBasicInfosRequest listMediaBasicInfosRequest = new ListMediaBasicInfosRequest();
ListMediaBasicInfosResponse listMediaBasicInfosResponse = client.listMediaBasicInfos(listMediaBasicInfosRequest);
System.out.println("MaxResults : " + listMediaBasicInfosResponse.getBody().getMaxResults());
if (listMediaBasicInfosResponse.getBody().getMediaInfos() != null &&
listMediaBasicInfosResponse.getBody().getMediaInfos().size() > 0) {
System.out.println("size : " + listMediaBasicInfosResponse.getBody().getMediaInfos().size());
System.out.println("mediaid : " + listMediaBasicInfosResponse.getBody().getMediaInfos().get(0).getMediaId());
}
}
}
相关接口
文档内容是否对您有帮助?