This topic provides API call examples for the media asset management module of the Java software development kit (SDK). It includes searching for media asset information, retrieving video information, modifying video information, deleting videos, retrieving source file information, retrieving image information, and deleting image information.
API call notes
In this topic, an AccessKey pair is used to initialize a client instance in the code examples.
For detailed descriptions of the API parameters and returned fields, visit the Alibaba Cloud OpenAPI Portal and view the Documentation tab for each API.
This topic provides code examples for only some complex APIs. To obtain SDK code examples for other APIs, go to the Alibaba Cloud OpenAPI Portal. On the Parameter Settings tab on the left, enter the required parameter information and initiate the call. Then, on the SDK Sample tab on the right, select the SDK version and target language to view and download the sample code.
The API calls in this topic use SDK V1.0 as an example. To obtain SDK examples for V2.0, specify the corresponding SDK version when you obtain the sample code from the Alibaba Cloud OpenAPI Portal.

Initialize the client
Before you start, initialize the client. For more information, see Initialization.
Search for media asset information
You can call the SearchMedia API to generate an SDK example to search for media asset information.
Alibaba Cloud OpenAPI Portal: SearchMedia.
The following is an example:
import com.aliyuncs.auth.AlibabaCloudCredentials;
import com.aliyuncs.auth.EnvironmentVariableCredentialsProvider;
import com.aliyuncs.vod.model.v20170321.SearchMediaRequest;
import com.aliyuncs.vod.model.v20170321.SearchMediaResponse;
/**
*Read AccessKey information
*/
public static DefaultAcsClient initVodClient() throws ClientException {
String regionId = "cn-shanghai"; // The region where the video-on-demand service is activated.
// An Alibaba Cloud account AccessKey has full access permissions to all APIs. We recommend that you use a Resource Access Management (RAM) user for API calls and daily O&M.
// We strongly recommend that you do not hard-code your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked and the security of all resources in your account may be compromised.
// This example shows how to use an environment variable to obtain an AccessKey for identity verification. Before you run the example code, configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.
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 requests.
* @return SearchMediaResponse The response data for searching for media asset information.
* @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");
}Get audio or video information
You can call the GetVideoInfo API to generate an SDK example for retrieving information about a single audio or video file.
Alibaba Cloud OpenAPI Portal: GetVideoInfo.
You can call the GetVideoInfos API to generate an SDK example for retrieving information about multiple audio or video files in a batch.
Alibaba Cloud OpenAPI Portal: GetVideoInfos.
Modify information about a single audio or video file
You can call the UpdateVideoInfo API to generate an SDK example for modifying information about a single audio or video file.
Alibaba Cloud OpenAPI Portal: UpdateVideoInfo.
Modify information about multiple audio or video files in a batch
You can call the UpdateVideoInfos API to generate an SDK example for modifying information about multiple audio or video files in a batch.
Alibaba Cloud OpenAPI Portal: UpdateVideoInfos.
The following is an example:
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;
/**
*Read AccessKey information
*/
public static DefaultAcsClient initVodClient() throws ClientException {
String regionId = "cn-shanghai"; // The region where the video-on-demand service is activated.
// An Alibaba Cloud account AccessKey has full access permissions to all APIs. We recommend that you use a Resource Access Management (RAM) user for API calls and daily O&M.
// We strongly recommend that you do not hard-code your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked and the security of all resources in your account may be compromised.
// This example shows how to use an environment variable to obtain an AccessKey for identity verification. Before you run the example code, configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.
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 videos in a batch
* @param client The client that sends requests.
* @return UpdateVideoInfosResponse The response data for modifying information about multiple videos in a batch.
* @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");
}Get source file information (including download URLs)
You can call the GetMezzanineInfo API to generate an SDK example for retrieving source file information.
Alibaba Cloud OpenAPI Portal: GetMezzanineInfo.
Get a list of audio or video files
You can call the GetVideoList API to generate an SDK example for retrieving a list of audio or video files.
Alibaba Cloud OpenAPI Portal: GetVideoList.
Delete audio or video files
You can call the DeleteVideo API to generate an SDK example for deleting audio or video files.
Alibaba Cloud OpenAPI Portal: DeleteVideo.
Delete media streams
You can call the DeleteStream API to generate an SDK example for deleting media streams.
Alibaba Cloud OpenAPI Portal: DeleteStream.
Delete source files in a batch
You can call the DeleteMezzanines API to generate an SDK example for deleting source files in a batch.
Alibaba Cloud OpenAPI Portal: DeleteMezzanines.
Update image information in a batch
You can call the UpdateImageInfos API to generate an SDK example for updating image information in a batch.
Alibaba Cloud OpenAPI Portal: UpdateImageInfos.
The following is an example:
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;
/**
*Read AccessKey information
*/
public static DefaultAcsClient initVodClient() throws ClientException {
String regionId = "cn-shanghai"; // The region where the video-on-demand service is activated.
// An Alibaba Cloud account AccessKey has full access permissions to all APIs. We recommend that you use a Resource Access Management (RAM) user for API calls and daily O&M.
// We strongly recommend that you do not hard-code your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked and the security of all resources in your account may be compromised.
// This example shows how to use an environment variable to obtain an AccessKey for identity verification. Before you run the example code, configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.
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;
}
/**
* The function to update image information in a batch
* @param client The client that sends requests.
* @return UpdateImageInfosResponse The response data for updating image information in a batch.
* @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");
}Get image information
You can call the GetImageInfo API to generate an SDK example for retrieving image information.
Alibaba Cloud OpenAPI Portal: GetImageInfo.
Delete images
You can call the DeleteImage API to generate an SDK example for deleting images.
Alibaba Cloud OpenAPI Portal: DeleteImage.
The following is an example:
import com.aliyuncs.auth.AlibabaCloudCredentials;
import com.aliyuncs.auth.EnvironmentVariableCredentialsProvider;
import com.aliyuncs.vod.model.v20170321.DeleteImageRequest;
import com.aliyuncs.vod.model.v20170321.DeleteImageResponse;
/**
*Read AccessKey information
*/
public static DefaultAcsClient initVodClient() throws ClientException {
String regionId = "cn-shanghai"; // The region where the video-on-demand service is activated.
// An Alibaba Cloud account AccessKey has full access permissions to all APIs. We recommend that you use a Resource Access Management (RAM) user for API calls and daily O&M.
// We strongly recommend that you do not hard-code your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked and the security of all resources in your account may be compromised.
// This example shows how to use an environment variable to obtain an AccessKey for identity verification. Before you run the example code, configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.
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;
}
/**
* The function to delete images
*
* @param client The client that sends requests.
* @return DeleteImageResponse The response data for deleting images.
* @throws Exception
*/
public static DeleteImageResponse deleteImage(DefaultAcsClient client) throws Exception {
DeleteImageRequest request = new DeleteImageRequest();
// Delete image files based on ImageURLs.
request.setDeleteImageType("ImageURL");
// Example 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 ImageIds.
//request.setDeleteImageType("ImageId");
//request.setImageIds("ImageId1,ImageId2");
// Delete image files of a specified ImageType based on a 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");
}