All Products
Search
Document Center

Media asset management

Last Updated: Jul 11, 2019

Initialize a client

Initialize a client before using the SDK. For more information, see initVodClient.

Search for media asset information

For more information about the request and response parameters, see SearchMedia.

import com.aliyuncs.vod.model.v20170321.SearchMediaRequest;
import com.aliyuncs.vod.model.v20170321.SearchMediaResponse;

/**
 * Method for searching for media asset information
 * @param client The client that sends a request.
 * @return SearchMediaResponse The response to the request 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);
}

// Call example
public static void main(String[] argv) {
    DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    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");
}

Obtain video information

For more information about the request and response parameters, see GetVideoInfo.

import com.aliyuncs.vod.model.v20170321.GetVideoInfoRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoInfoResponse;

/**
 * Method for obtaining video information
 * @param client The client that sends a request.
 * @return GetVideoInfoResponse The response to the request for obtaining video information.
 * @throws Exception
*/
public static GetVideoInfoResponse getVideoInfo(DefaultAcsClient client) throws Exception {
    GetVideoInfoRequest request = new GetVideoInfoRequest();
    request.setVideoId("VideoId");
    return client.getAcsResponse(request);
}

// Call example
public static void main(String[] argv) {
    DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    GetVideoInfoResponse response = new GetVideoInfoResponse();
    try {
        response = getVideoInfo(client);
        System.out.print("Title = " + response.getVideo().getTitle() + "\n");
        System.out.print("Description = " + response.getVideo().getDescription() + "\n");
    } catch (Exception e) {
        System.out.print("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.print("RequestId = " + response.getRequestId() + "\n");
}

Obtain the information about multiple videos

For more information about the request and response parameters, see GetVideoInfos.

import com.aliyuncs.vod.model.v20170321.GetVideoInfosRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoInfosResponse;

/**
 * Method for obtaining the information about multiple videos
 * @param client The client that sends a request.
 * @return GetVideoInfosResponse The response to the request for obtaining the information about multiple videos.
 * @throws Exception
*/
public static GetVideoInfosResponse getVideoInfos(DefaultAcsClient client) throws Exception {
    GetVideoInfosRequest request = new GetVideoInfosRequest();
    request.setVideoIds("VideoId1,VideoId2");
    return client.getAcsResponse(request);
}

// Call example
public static void main(String[] argv) {
    DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    GetVideoInfosResponse response = new GetVideoInfosResponse();
    try {
        response = getVideoInfos(client);
        if (response.getVideoList() ! = null && response.getVideoList().size() > 0) { 
            System.out.print("===== exist video infos : ===== \n");
            for (GetVideoInfosResponse.Video video : response.getVideoList()) {
                System.out.print("VideoId = " + video.getVideoId() + "\n");
                System.out.print("Title = " + video.getTitle() + "\n");
                System.out.print("Description = " + video.getDescription() + "\n");
                System.out.print("Tags = " + video.getTags() + "\n");
                System.out.print("CreationTime = " + video.getCreationTime() + "\n");
            }
        }
        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");
}

Modify video information

For more information about the request and response parameters, see UpdateVideoInfo.

import com.aliyuncs.vod.model.v20170321.UpdateVideoInfoRequest;
import com.aliyuncs.vod.model.v20170321.UpdateVideoInfoResponse;

/**
 * Method for modifying video information
 * @param client The client that sends a request.
 * @return UpdateVideoInfoResponse The response to the request for modifying video information.
 * @throws Exception
*/
public static UpdateVideoInfoResponse updateVideoInfo(DefaultAcsClient client) throws Exception {
    UpdateVideoInfoRequest request = new UpdateVideoInfoRequest();
    request.setVideoId("VideoId");
    request.setTitle("new Title");
    request.setDescription("new Description");
    request.setTags("new Tag1,new Tag2");
    return client.getAcsResponse(request);
}

// Call example
public static void main(String[] argv) {
    DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    UpdateVideoInfoResponse response = new UpdateVideoInfoResponse();
    try {
        response = updateVideoInfo(client);
    } catch (Exception e) {
        System.out.print("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.print("RequestId = " + response.getRequestId() + "\n");
}

Modify the information about multiple videos

For more information about the request and response parameters, see UpdateVideoInfos.

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

/**
 * Method for modifying the information about multiple videos
 * @param client The client that sends a request.
 * @return UpdateVideoInfosResponse The response to the request for modifying the information about multiple videos.
 * @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());
    DefaultAcsClient client = init();
    return client.getAcsResponse(request);
}

// Call example
public static void main(String[] argv) {
    DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    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");
}

Delete videos

For more information about the request and response parameters, see DeleteVideo.

import com.aliyuncs.vod.model.v20170321.DeleteVideoRequest;
import com.aliyuncs.vod.model.v20170321.DeleteVideoResponse;

/**
 * Method for deleting videos
 * @param client The client that sends a request.
 * @return DeleteVideoResponse The response to the request for deleting videos.
 * @throws Exception
*/
public static DeleteVideoResponse deleteVideo(DefaultAcsClient client) throws Exception {
    DeleteVideoRequest request = new DeleteVideoRequest();
    // Specifies one or more IDs of the videos to be deleted. Separate multiple video IDs with a comma (,).
    request.setVideoIds("VideoId1,VideoId2");
    return client.getAcsResponse(request);
}

/*Call example*/
public static void main(String[] argv) {
    DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    DeleteVideoResponse response = new DeleteVideoResponse();
    try {
        response = deleteVideo(client);
    } catch (Exception e) {
        System.out.print("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.print("RequestId = " + response.getRequestId() + "\n");
}

Obtain mezzanine file information (including the mezzanine file download URL)

For more information about the request and response parameters, see GetMezzanineInfo.

import com.aliyuncs.vod.model.v20170321.GetMezzanineInfoRequest;
import com.aliyuncs.vod.model.v20170321.GetMezzanineInfoResponse;

/**
 * Method for obtaining mezzanine file information
 * @param client The client that sends a request.
 * @return GetMezzanineInfoResponse The response to the request for obtaining mezzanine file information.
 * @throws Exception
*/
public static GetMezzanineInfoResponse getMezzanineInfo(DefaultAcsClient client) throws Exception {
    GetMezzanineInfoRequest request = new GetMezzanineInfoRequest();
    request.setVideoId("VideoId");
    // Sets the expiration time of the mezzanine file download URL.
    request.setAuthTimeout(3600L);
    return client.getAcsResponse(request);
}

// Call example
public static void main(String[] argv) {
    DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    GetMezzanineInfoResponse response = new GetMezzanineInfoResponse();
    try {
        response = getMezzanineInfo(client);
        System.out.print("Mezzanine.VideoId = " + response.getMezzanine().getVideoId() + "\n");
        System.out.print("Mezzanine.FileURL = " + response.getMezzanine().getFileURL() + "\n");
        System.out.print("Mezzanine.Width = " + response.getMezzanine().getWidth() + "\n");
        System.out.print("Mezzanine.Height = " + response.getMezzanine().getWidth() + "\n");
        System.out.print("Mezzanine.Size = " + response.getMezzanine().getSize() + "\n");
    } catch (Exception e) {
        System.out.print("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.print("RequestId = " + response.getRequestId() + "\n");
}

Obtain a video list

For more information about the request and response parameters, see GetVideoList.

import com.aliyuncs.vod.model.v20170321.GetVideoListRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoListResponse;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

// Generates a UTC time based on the date.
public static String generateUTCTime(Date time) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    dateFormat.setTimeZone(new SimpleTimeZone(SimpleTimeZone.UTC_TIME, "UTC"));
    dateFormat.setLenient(false);
    return dateFormat.format(time);
}

/**
 * Method for obtaining a video list
 * @param client The client that sends a request.
 * @return GetVideoListResponse The response to the request for obtaining a video list.
 * @throws Exception
*/
public static GetVideoListResponse getVideoList(DefaultAcsClient client) throws Exception {
    GetVideoListRequest request = new GetVideoListRequest();
    // Sets the start time to one month ago (in UTC) and the end time to the current time (in UTC) for filtering videos.
    String monthAgoUTCTime = generateUTCTime(new Date(System.currentTimeMillis() - 30 * 86400L));
    String nowUTCTime = generateUTCTime(new Date(System.currentTimeMillis()));
    // Sets the start time for video creation, in UTC.
    request.setStartTime(monthAgoUTCTime);
    // Sets the end time for video creation, in UTC.
    request.setEndTime(nowUTCTime);
    // Sets the video status. By default, videos in all statuses are obtained. Separate multiple video statuses with a comma (,).
    // request.setStatus("Uploading,Normal,Transcoding");
    request.setPageNo(1L);
    request.setPageSize(20L);
    return client.getAcsResponse(request);
}

// Call example
public static void main(String[] argv) {
    DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    GetVideoListResponse response = new GetVideoListResponse();
    try {
        response = getVideoList(client);
        // The total number of videos that are found based on the specified filter criteria.
        System.out.print("Total = " + response.getTotal() + "\n");
        for (GetVideoListResponse.Video video : response.getVideoList()) {
            System.out.print("Title = " + video.getTitle() + "\n");
            System.out.print("Description = " + video.getDescription() + "\n");
            System.out.print("Tags = " + video.getTags() + "\n");
            System.out.print("CreationTime = " + video.getCreationTime() + "\n");
        }
    } catch (Exception e) {
        System.out.print("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.print("RequestId = " + response.getRequestId() + "\n");
}

Delete media streams

For more information about the request and response parameters, see DeleteStream.

import com.aliyuncs.vod.model.v20170321.DeleteStreamRequest;
import com.aliyuncs.vod.model.v20170321.DeleteStreamResponse;

/**
 * Method for deleting media streams
 * @param client The client that sends a request.
 * @return DeleteMezzaninesResponse The response to the request for deleting media streams.
 * @throws Exception
*/
public static DeleteStreamResponse deleteStream(DefaultAcsClient client) throws Exception {
    DeleteStreamRequest request = new DeleteStreamRequest();
    request.setVideoId("VideoId");
    request.setJobIds("JobId1,JobId2");
    return client.getAcsResponse(request);
}

// Call example
public static void main(String[] argv) {
    DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    DeleteStreamResponse response = new DeleteStreamResponse();
    try {
        response = deleteStream(client);
    } catch (Exception e) {
        System.out.print("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.print("RequestId = " + response.getRequestId() + "\n");
}

Delete multiple mezzanine files

For more information about the request and response parameters, see DeleteMezzanines.

import com.aliyuncs.vod.model.v20170321.DeleteMezzaninesRequest;
import com.aliyuncs.vod.model.v20170321.DeleteMezzaninesResponse;
/**
 * Method for deleting multiple mezzanine files
 * @param client The client that sends a request.
 * @return DeleteMezzaninesResponse The response to the request for deleting multiple mezzanine files.
 * @throws Exception
*/
public static DeleteMezzaninesResponse deleteMezzanines(DefaultAcsClient client) throws Exception {
    DeleteMezzaninesRequest request = new DeleteMezzaninesRequest();
    // Specifies one or more IDs of the videos to be deleted. Separate multiple video IDs with a comma (,).
    request.setVideoIds("VideoId1,VideoId2");
    request.setForce(false);
    return client.getAcsResponse(request);
}

// Call example
public static void main(String[] argv) {
    DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    DeleteMezzaninesResponse response = new DeleteMezzaninesResponse();
    try {
        response = deleteMezzanines(client);
    } catch (Exception e) {
        System.out.print("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.print("RequestId = " + response.getRequestId() + "\n");
}

Update the information about multiple images

For more information about the request and response parameters, see UpdateImageInfos.

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

/**
 * Method for updating the information about multiple images
 * @param client The client that sends a request.
 * @return UpdateImageInfosResponse The response to the request for updating the information about multiple images.
 * @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);
    }

// Call example
public static void main(String[] argv) throws Exception {
    DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    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");
}

Obtain image information

For more information about the request and response parameters, see GetImageInfo.

import com.aliyuncs.vod.model.v20170321.GetImageInfoRequest;
import com.aliyuncs.vod.model.v20170321.GetImageInfoResponse;

/**
 * Method for obtaining image information
 *
 * @param client The client that sends a request.
 * @return GetImageInfoResponse The response to the request for obtaining image information.
 * @throws Exception
*/
public static GetImageInfoResponse getImageInfo(DefaultAcsClient client) throws Exception {
    GetImageInfoRequest request = new GetImageInfoRequest();
    request.setImageId("ImageId");
    return client.getAcsResponse(request);
}

// Call example
public static void main(String[] argv) throws ClientException {
    DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    GetImageInfoResponse response = new GetImageInfoResponse();
    try {
        response = getImageInfo(client);
        System.out.print("ImageId=" + response.getImageInfo().getImageId());
        System.out.print("Title=" + response.getImageInfo().getTitle());
        System.out.print("CreationTime=" + response.getImageInfo().getCreationTime());
        System.out.print("FileURL=" + response.getImageInfo().getMezzanine().getFileURL());
    } catch (Exception e) {
        System.out.print("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.print("RequestId = " + response.getRequestId() + "\n");
}

Delete images

For more information about the request and response parameters, see DeleteImage.

import com.aliyuncs.vod.model.v20170321.DeleteImageRequest;
import com.aliyuncs.vod.model.v20170321.DeleteImageResponse;

/**
 * Method for deleting images
 *
 * @param client The client that sends a request.
 * @return DeleteImageResponse The response to the request for deleting images.
 * @throws Exception
*/
public static DeleteImageResponse deleteImage(DefaultAcsClient client) throws Exception {
    DeleteImageRequest request = new DeleteImageRequest();
    // Deletes image files based on image URLs.
    request.setDeleteImageType("ImageURL");
    String url = "http://sample.aliyun.com/cover.jpg";
    String encodeUrl = URLEncoder.encode(url, "UTF-8");
    request.setImageURLs(encodeUrl);
    // Deletes image files based on image IDs.
    //request.setDeleteImageType("ImageId");
    //request.setImageIds("ImageId1,ImageId2");
    // Deletes image files of the specified image type based on a video ID.
    //request.setDeleteImageType("VideoId");
    //request.setVideoId("VideoId");
    //request.setImageType("SpriteSnapshot");
    return client.getAcsResponse(request);
}

// Call example
public static void main(String[] argv) throws ClientException {
    DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    DeleteImageResponse response = new DeleteImageResponse();
    try {
        response = deleteImage(client);
    } catch (Exception e) {
        System.out.print("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.print("RequestId = " + response.getRequestId() + "\n");
}