All Products
Search
Document Center

Snapshot template

Last Updated: Jul 11, 2019

Initialize a client

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

Add a snapshot template

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

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.vod.model.v20170321.AddVodTemplateRequest;
import com.aliyuncs.vod.model.v20170321.AddVodTemplateResponse;

/**
 * Method for constructing the configuration of a snapshot template. Modify parameters as required.
 * (The following sample code shows the complete sprite snapshot configuration.)
 * @return
 */
public static JSONObject buildSnapshotTemplateConfig() {
    JSONObject templateConfig = new JSONObject();
    JSONObject snapshotConfig = new JSONObject();
    snapshotConfig.put("Count", "50");
    snapshotConfig.put("Interval", "1");
    snapshotConfig.put("SpecifiedOffsetTime", "0");
    snapshotConfig.put("Width", "200");
    snapshotConfig.put("Height", "200");
    snapshotConfig.put("FrameType", "normal");
    // Specifies the normal snapshot configuration, which is shared with the original sprite snapshot configuration.
    templateConfig.put("SnapshotConfig", snapshotConfig);

    // Specifies the sprite snapshot configuration, which must be constructed based on the normal snapshot configuration.
    JSONObject spriteSnapshotConfig = new JSONObject();
    spriteSnapshotConfig.put("CellWidth", "120");
    spriteSnapshotConfig.put("CellHeight", "68");
    spriteSnapshotConfig.put("Columns", "3");
    spriteSnapshotConfig.put("Lines", "10");
    spriteSnapshotConfig.put("Padding", "20");
    spriteSnapshotConfig.put("Margin", "50");
    spriteSnapshotConfig.put("KeepCellPic", "keep");
    spriteSnapshotConfig.put("Color", "tomato");
    snapshotConfig.put("SpriteSnapshotConfig", spriteSnapshotConfig);

    // Sets the snapshot type. If the sprite snapshot is configured, set the value to SpriteSnapshot. If the sprite snapshot is not configured, set the value to NormalSnapshot.
    templateConfig.put("SnapshotType", "SpriteSnapshot");
    return templateConfig;
}

/**
 * Method for adding a snapshot template
 */
public static AddVodTemplateResponse addSnapshotVodTemplate(DefaultAcsClient client) throws Exception {
    AddVodTemplateRequest request = new AddVodTemplateRequest();
    // Sets the template name.
    request.setName("AddVodTemplate test");
    // Sets the template type to Snapshot.
    request.setTemplateType("Snapshot");
    // Generates the snapshot template configuration.
    JSONObject templateConfig = buildSnapshotTemplateConfig();
    request.setTemplateConfig(templateConfig.toJSONString());
    return client.getAcsResponse(request);
}

/**
 * Call example
 * @param args
 * @throws ClientException
 */
public static void main(String[] args) {
    DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    AddVodTemplateResponse response = new AddVodTemplateResponse();
    try {
        // Adds a snapshot template and obtain a response.
        response = addSnapshotVodTemplate(client);
        // The snapshot template ID.
        System.out.println("SnapshotVodTemplateId = " + response.getVodTemplateId());
    } catch (Exception e) {
        System.out.println("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.println("RequestId = " + response.getRequestId());
}

Modify a snapshot template

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

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.vod.model.v20170321.UpdateVodTemplateRequest;
import com.aliyuncs.vod.model.v20170321.UpdateVodTemplateResponse;

/**
 * Method for constructing the configuration of a snapshot template. Modify parameters as required.
 * (The following sample code shows the complete normal snapshot configuration.)
 * @return
 */
public static JSONObject buildSnapshotTemplateConfig() {
    JSONObject templateConfig = new JSONObject();
    JSONObject snapshotConfig = new JSONObject();
    snapshotConfig.put("Count", "50");
    snapshotConfig.put("Interval", "1");
    snapshotConfig.put("SpecifiedOffsetTime", "0");
    snapshotConfig.put("Width", "200");
    snapshotConfig.put("Height", "200");
    snapshotConfig.put("FrameType", "normal");
    // Specifies the normal snapshot configuration, which is shared with the original sprite snapshot configuration.
    templateConfig.put("SnapshotConfig", snapshotConfig);

    // Sets the snapshot type. If the sprite snapshot is configured, set the value to SpriteSnapshot. If the sprite snapshot is not configured, set the value to NormalSnapshot.
    templateConfig.put("SnapshotType", "NormalSnapshot");
    return templateConfig;
}

/**
 * Method for modifying a snapshot template
 */
public static UpdateVodTemplateResponse updateSnapshotVodTemplate(DefaultAcsClient client) throws Exception {
    UpdateVodTemplateRequest request = new UpdateVodTemplateRequest();
    // Specifies the ID of the template to be modified.
    request.setVodTemplateId("53azf9d796fad9d7b862b2e5e5b");
    // Sets the template name.
    request.setName("UpdateVodTemplate test");
    // Generates the snapshot template configuration.
    JSONObject templateConfig = buildSnapshotTemplateConfig();
    request.setTemplateConfig(templateConfig.toJSONString());
    return client.getAcsResponse(request);
}

/**
 * Call example
 * @param args
 * @throws ClientException
 */
public static void main(String[] args) {
    DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    UpdateVodTemplateResponse response = new UpdateVodTemplateResponse();
    try {
        // Modifies a snapshot template.
        response = updateSnapshotVodTemplate(client);
        // The snapshot template ID.
        System.out.println("SnapshotVodTemplateId = " + response.getVodTemplateId());
    } catch (Exception e) {
        System.out.println("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.println("RequestId = " + response.getRequestId());
}

Delete a snapshot template

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

import com.aliyuncs.vod.model.v20170321.DeleteVodTemplateRequest;
import com.aliyuncs.vod.model.v20170321.DeleteVodTemplateResponse;

/**
 * Method for deleting a snapshot template
 */
public static DeleteVodTemplateResponse deleteSnapshotVodTemplate(DefaultAcsClient client) throws Exception  
    DeleteVodTemplateRequest request = new DeleteVodTemplateRequest();
    // Specifies the ID of the template to be deleted.
    request.setVodTemplateId("53azf9d796fad9d7b862b2e5e5b");
    return client.getAcsResponse(request);
}

/**
 * Call example
 * @param args
 * @throws ClientException
 */
public static void main(String[] args) {
DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    DeleteVodTemplateResponse response = new DeleteVodTemplateResponse();
    try {
        // Deletes a snapshot template.
        response = deleteSnapshotVodTemplate(client);
    } catch (Exception e) {
        System.out.println("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.println("RequestId = " + response.getRequestId());
}

Query a list of snapshot templates

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

import com.aliyuncs.vod.model.v20170321.ListVodTemplateRequest;
import com.aliyuncs.vod.model.v20170321.ListVodTemplateResponse;

/**
 * Method for querying a list of snapshot templates
 */
public static ListVodTemplateResponse listSnapshotVodTemplate(DefaultAcsClient client) throws Exception {
    ListVodTemplateRequest request = new ListVodTemplateRequest();
    // Sets the template type to Snapshot.
    request.setTemplateType("Snapshot");
    return client.getAcsResponse(request);
}

/**
 * Call example
 * @param args
 * @throws ClientException
 */
public static void main(String[] args) {
    DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    ListVodTemplateResponse response = new ListVodTemplateResponse();
    try {
        // Queries a list of snapshot templates.
        response = listSnapshotVodTemplate(client);
        // The number of templates that are found.
        System.out.println("SnapshotVodTemplateId = " + response.getVodTemplateInfoList().size());
    } catch (Exception e) {
        System.out.println("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.println("RequestId = " + response.getRequestId());
}

Query a snapshot template

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

import com.aliyuncs.vod.model.v20170321.GetVodTemplateRequest;
import com.aliyuncs.vod.model.v20170321.GetVodTemplateResponse;

/**
* Method for querying a snapshot template
*/
public static GetVodTemplateResponse getSnapshotVodTemplate(DefaultAcsClient client) throws Exception {
    GetVodTemplateRequest request = new GetVodTemplateRequest();
    // Specifies the ID of the template to be queried.
    request.setVodTemplateId("53azf9d796fad9d7b862b2e5e5b");
    return client.getAcsResponse(request);
}

/**
 * Call example
 * @param args
 * @throws ClientException
 */
public static void main(String[] args) {
    DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    GetVodTemplateResponse response = new GetVodTemplateResponse();
    try {
        // Queries a snapshot template and obtain a response.
        response = getSnapshotVodTemplate(client);
        // The returned snapshot template ID.
        System.out.println("SnapshotVodTemplateId = " + response.getVodTemplateInfo().getVodTemplateId());
    } catch (Exception e) {
        System.out.println("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.println("RequestId = " + response.getRequestId());
}