通過閱讀本文,您可以了解通過服務端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());
}
}
}
相關接口
文檔內容是否對您有幫助?