All Products
Search
Document Center

ApsaraVideo VOD:Media asset management

Last Updated:Aug 22, 2023

This topic provides examples on how to use the API operations of the media management module. The API operations are encapsulated in ApsaraVideo VOD SDK for Java. You can call the API operations to search for media asset information, modify video information, and query source file information. You can also query and delete videos and images.

Usage notes

  • In this example, an AccessKey pair is used to initialize a client instance.

  • For more information about the request and response parameters of this operation, visit OpenAPI Explorer. You can click API Documentation in the top navigation bar to view information related to the API operation.

  • This topic provides sample code only for some complex API operations. To obtain sample code for other API operations, perform the following operations: Visit Alibaba Cloud OpenAPI Explorer. In the left-side navigation pane, find the API operation whose sample code you want to obtain and specify the required parameters on the Parameters tab. Then, click Initiate Call. On the SDK Sample Code tab, select the language to view and download the sample code.

Initialize a client

Before you use the SDK, initialize a client. For more information, see Initialization.

Query media asset information

You can call the SearchMedia operation to query media asset information.

Click SearchMedia to learn more about this API operation.

Sample code:

import com.aliyuncs.auth.AlibabaCloudCredentials;
import com.aliyuncs.auth.EnvironmentVariableCredentialsProvider;
import com.aliyuncs.vod.model.v20170321.SearchMediaRequest;
import com.aliyuncs.vod.model.v20170321.SearchMediaResponse;

 /**
   * Obtain the AccessKey information.
   */
    public static DefaultAcsClient initVodClient() throws ClientException {
    String regionId = "cn-shanghai";  // Specify the region in which ApsaraVideo VOD is activated.
    // The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine O&M. 
    // We recommend that you do not save your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked. As a result, the security of all resources in your account is compromised. 
    // In this example, the system reads the AccessKey pair from environment variables to implement authentication for API access. Before you run the sample code, configure the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET. 
    DefaultProfile profile = DefaultProfile.getProfile(regionId, System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
    DefaultAcsClient client = new DefaultAcsClient(profile);
    return client;
}
/**
 * Search for media asset information.
 * @param client The client that sends a request.
 * @return SearchMediaResponse The information contained in the response.
 * @throws Exception
 */
public static SearchMediaResponse searchMedia(DefaultAcsClient client) throws Exception {
    SearchMediaRequest request = new SearchMediaRequest();
    request.setFields("Title,CoverURL,Status");
    request.setMatch("Status in ('Normal','Checking') and CreationTime = ('2018-07-01T08:00:00Z','2018-08-01T08:00:00Z')");
    request.setPageNo(1);
    request.setPageSize(10);
    request.setSearchType("video");
    request.setSortBy("CreationTime:Desc");
    return client.getAcsResponse(request);
}

// Sample request
public static void main(String[] argv) {
    DefaultAcsClient client = initVodClient();
    SearchMediaResponse response = new SearchMediaResponse();
    try {
        response = searchMedia(client);
        if (response.getMediaList() != null && response.getMediaList().size() > 0) {
            System.out.print("Total = " + response.getTotal() + "\n");
            System.out.print("ScrollToken = " + response.getScrollToken() + "\n");
            for (SearchMediaResponse.Media media : response.getMediaList()) {
                System.out.print("MediaId = " + media.getMediaId() + "\n");
                System.out.print("MediaType = " + media.getMediaType() + "\n");
                System.out.print("CreationTime = " + media.getCreationTime() + "\n");
                System.out.print("Title = " + media.getVideo().getTitle() + "\n");
                System.out.print("CoverURL = " + media.getVideo().getCoverURL() + "\n");
                System.out.print("Status = " + media.getVideo().getStatus() + "\n");
            }
        }
    } catch (Exception e) {
        System.out.print("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.print("RequestId = " + response.getRequestId() + "\n");
}

Query information about audio or video files

  • You can call the GetVideoInfo operation to query information about an audio or video file.

    Click GetVideoInfo to learn more about this API operation.

  • You can call the GetVideoInfos operation to query information about multiple audio or video files at a time.

    Click GetVideoInfos to learn more about this API operation.

Modify information about an audio or video file

You can call the UpdateVideoInfo operation to modify information about an audio or video file.

Click UpdateVideoInfo to learn more about this API operation.

Modify information about multiple audio or video files

You can call the UpdateVideoInfos operation to modify information about multiple audio or video files at a time.

Click UpdateVideoInfos to learn more about this API operation.

Sample code:

import com.aliyuncs.auth.AlibabaCloudCredentials;
import com.aliyuncs.auth.EnvironmentVariableCredentialsProvider;
import com.aliyuncs.vod.model.v20170321.UpdateVideoInfosRequest;
import com.aliyuncs.vod.model.v20170321.UpdateVideoInfosResponse;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

 /**
   * Obtain the AccessKey information.
   */
    public static DefaultAcsClient initVodClient() throws ClientException {
    String regionId = "cn-shanghai";  // Specify the region in which ApsaraVideo VOD is activated.
    // The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine O&M. 
    // We recommend that you do not save your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked. As a result, the security of all resources in your account is compromised. 
    // In this example, the system reads the AccessKey pair from environment variables to implement authentication for API access. Before you run the sample code, configure the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET. 
    DefaultProfile profile = DefaultProfile.getProfile(regionId, System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
    DefaultAcsClient client = new DefaultAcsClient(profile);
    return client;
}
/**
 * Modify information about multiple video files at a time.
 * @param client The client that sends a request.
 * @return UpdateVideoInfosResponse The information contained in the response.
 * @throws Exception
*/
public static UpdateVideoInfosResponse updateVideoInfos(DefaultAcsClient client) throws Exception {
    UpdateVideoInfosRequest request = new UpdateVideoInfosRequest();
    JSONArray updateContentArray = new JSONArray();
    JSONObject updateContent1 = new JSONObject();
    updateContent1.put("VideoId", "VideoId1");
    // updateContent1.put("Title", "new Title");
    // updateContent1.put("Tags", "new Tag1,new Tag2");
    updateContentArray.add((updateContent1));
    JSONObject updateContent2 = new JSONObject();
    updateContent2.put("VideoId", "VideoId2");
    // updateContent2.put("Title", "new Title");
    // updateContent2.put("Tags", "new Tag1,new Tag2");
    updateContentArray.add((updateContent2));
    request.setUpdateContent(updateContentArray.toJSONString());
    return client.getAcsResponse(request);
}

// Sample request
public static void main(String[] argv) {
    DefaultAcsClient client = initVodClient();
    UpdateVideoInfosResponse response = new UpdateVideoInfosResponse();
    try {
        response = updateVideoInfos(client);
        if (response.getNonExistVideoIds() != null && response.getNonExistVideoIds().size() > 0) {
            System.out.print("======nonexistent VideoIds : ======\n");
            for (String videoId : response.getNonExistVideoIds()) {
                System.out.print(videoId + "\n");
            }
        }
    } catch (Exception e) {
        System.out.print("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.print("RequestId = " + response.getRequestId() + "\n");
}

Query source file information (the download URL included)

You can call the GetMezzanineInfo operation to query source file information.

Click GetMezzanineInfo to learn more about this API operation.

Query audio and video files

You can call the GetVideoList operation to query audio and video files.

Click GetVideoList to learn more about this API operation.

Delete audio and video files

You can call the DeleteVideo operation to delete audio and video files.

Click DeleteVideo to learn more about this API operation.

Delete media streams

You can call the DeleteStream operation to delete media streams.

Click DeleteStream to learn more about this API operation.

Delete multiple source files

You can call the DeleteMezzanines operation to delete multiple source files at a time.

Click DeleteMezzanines to learn more about this API operation.

Modify information about multiple images

You can call the UpdateImageInfos operation to modify information about multiple images at a time.

Click UpdateImageInfos to learn more about this API operation.

Sample code:

import com.aliyuncs.auth.AlibabaCloudCredentials;
import com.aliyuncs.auth.EnvironmentVariableCredentialsProvider;
import com.aliyuncs.vod.model.v20170321.UpdateImageInfosRequest;
import com.aliyuncs.vod.model.v20170321.UpdateImageInfosResponse;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

 /**
   * Obtain the AccessKey information.
   */
    public static DefaultAcsClient initVodClient() throws ClientException {
    String regionId = "cn-shanghai";  // Specify the region in which ApsaraVideo VOD is activated.
    // The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine O&M. 
    // We recommend that you do not save your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked. As a result, the security of all resources in your account is compromised. 
    // In this example, the system reads the AccessKey pair from environment variables to implement authentication for API access. Before you run the sample code, configure the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET. 
    DefaultProfile profile = DefaultProfile.getProfile(regionId, System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
    DefaultAcsClient client = new DefaultAcsClient(profile);
    return client;
}
/**
 * Modify information about multiple images at a time.
 * @param client The client that sends a request.
 * @return UpdateImageInfosResponse The information contained in the response.
 * @throws Exception
*/
public static UpdateImageInfosResponse updateImageInfos(DefaultAcsClient client) throws Exception{
        UpdateImageInfosRequest request = new UpdateImageInfosRequest();
        JSONArray updateContentArray = new JSONArray();
        JSONObject updateContent1 = new JSONObject();
        updateContent1.put("ImageId", "ImageId1");
//        updateContent1.put("Title", "new Title");
//        updateContent1.put("Tags", "new Tag1,new Tag2");
        updateContentArray.add((updateContent1));
        JSONObject updateContent2 = new JSONObject();
        updateContent2.put("ImageId", "ImageId2");
//        updateContent2.put("Title", "new Title");
//        updateContent2.put("Tags", "new Tag1,new Tag2");
        updateContentArray.add((updateContent2));
        request.setUpdateContent(updateContentArray.toJSONString());
        return client.getAcsResponse(request);
    }

// Sample request
public static void main(String[] argv) throws Exception {
    DefaultAcsClient client = initVodClient();
    UpdateImageInfosResponse response = new UpdateImageInfosResponse();
    try {
        response = updateImageInfos(client);
        if (response.getNonExistImageIds() != null && response.getNonExistImageIds().size() > 0) {
            System.out.print("======nonexistent ImageIds : ======\n");
            for (String imageId : response.getNonExistImageIds()) {
                System.out.print(imageId + "\n");
            }
        }
    } catch (Exception e) {
        System.out.print("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.print("RequestId = " + response.getRequestId() + "\n");
}

Query information about an image

You can call the GetImageInfo operation to query information about an image.

Click GetImageInfo to learn more about this API operation.

Delete images

You can call the DeleteImage operation to delete images.

Click DeleteImage to learn more about this API operation.

Sample code:

import com.aliyuncs.auth.AlibabaCloudCredentials;
import com.aliyuncs.auth.EnvironmentVariableCredentialsProvider;
import com.aliyuncs.vod.model.v20170321.DeleteImageRequest;
import com.aliyuncs.vod.model.v20170321.DeleteImageResponse;

 /**
   * Obtain the AccessKey information.
   */
    public static DefaultAcsClient initVodClient() throws ClientException {
    String regionId = "cn-shanghai";  // Specify the region in which ApsaraVideo VOD is activated.
    // The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine O&M. 
    // We recommend that you do not save your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked. As a result, the security of all resources in your account is compromised. 
    // In this example, the system reads the AccessKey pair from environment variables to implement authentication for API access. Before you run the sample code, configure the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET. 
    DefaultProfile profile = DefaultProfile.getProfile(regionId, System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
    DefaultAcsClient client = new DefaultAcsClient(profile);
    return client;
}
/**
 * Delete images.
 *
 * @param client The client that sends a request.
 * @return DeleteImageResponse The information contained in the response.
 * @throws Exception
*/
public static DeleteImageResponse deleteImage(DefaultAcsClient client) throws Exception {
    DeleteImageRequest request = new DeleteImageRequest();
    // Delete image files based on ImageURL.
    request.setDeleteImageType("ImageURL");
    // Example of ImageURL: http://example.aliyundoc.com/cover-****.jpg.
    String url = "<your image URL>";
    String encodeUrl = URLEncoder.encode(url, "UTF-8");
    request.setImageURLs(encodeUrl);
    // Delete image files based on ImageId.
    //request.setDeleteImageType("ImageId");
    //request.setImageIds("ImageId1,ImageId2");
    // Delete image files of a specified type based on VideoId.
    //request.setDeleteImageType("VideoId");
    //request.setVideoId("VideoId");
    //request.setImageType("SpriteSnapshot");
    return client.getAcsResponse(request);
}

// Sample request
public static void main(String[] argv) throws ClientException {
    DefaultAcsClient client = initVodClient();
    DeleteImageResponse response = new DeleteImageResponse();
    try {
        response = deleteImage(client);
    } catch (Exception e) {
        System.out.print("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.print("RequestId = " + response.getRequestId() + "\n");
}