全部产品

内容库管理

本文介绍如何通过ICE Java SDK进行内容库管理。

注册媒资内容

目前仅支持通过oss文件注册媒资内容

内容管理

通过SDK对内容进行增删改查操作。

通过 GetMediaInfo 接口获取内容基础信息、文件分析结果、AI分析结果。

通过 ListMediaBasicInfos 接口获取多个内容,支持分页。

代码示例

package com.aliyun.ice.sample;

import com.aliyun.ice20201109.models.*;
import com.aliyun.teaopenapi.models.*;
import com.aliyun.ice20201109.Client;

/**
 * @author :xxxxx
 * @date :Created in 2021/1/12
 */
public class MediaInfoSample {
    public static void main (String args[]) {
        try {
            // 初始化SDK
            Config config = new Config();
            config.accessKeyId = "<yourAccessKeyId>";
            config.accessKeySecret = "<yourAccessKeySecret>";
            config.endpoint = "ice.cn-shanghai.aliyuncs.com";
            config.regionId = "cn-shanghai";
            Client iceClient = new Client(config);

            // 注册媒资内容
            RegisterMediaInfoRequest registerMediaInfoRequest = new RegisterMediaInfoRequest();
            registerMediaInfoRequest.setInputURL("oss://test.sample.com/media/cover/mediaid.jpg");
            RegisterMediaInfoResponse registerMediaInfoResponse = iceClient.registerMediaInfo(registerMediaInfoRequest);
            String mediaId = registerMediaInfoResponse.getBody().getMediaId();
            System.out.println("mediaId : " + mediaId);

            // 获取单个内容
            GetMediaInfoRequest getMediaInfoRequest = new GetMediaInfoRequest();
            getMediaInfoRequest.setMediaId(mediaId);
            GetMediaInfoResponse getMediaInfoResponse = iceClient.getMediaInfo(getMediaInfoRequest);
            System.out.println("mediaId : " + getMediaInfoResponse.getBody().getMediaInfo().getMediaId());

            // 修改内容信息
            UpdateMediaInfoRequest updateMediaInfoRequest = new UpdateMediaInfoRequest();
            updateMediaInfoRequest.setMediaId(mediaId);
            updateMediaInfoRequest.setCoverURL("http://test.sample.com/media/cover/mediaid.jpg");
            iceClient.updateMediaInfo(updateMediaInfoRequest);

            // 删除内容信息
            DeleteMediaInfosRequest deleteMediaInfosRequest = new DeleteMediaInfosRequest();
            deleteMediaInfosRequest.setMediaIds(mediaId);
            iceClient.deleteMediaInfos(deleteMediaInfosRequest);

            // 搜索内容库
            ListMediaBasicInfosRequest listMediaBasicInfosRequest = new ListMediaBasicInfosRequest();
            ListMediaBasicInfosResponse listMediaBasicInfosResponse = iceClient.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());
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}