更新时间:2024-07-29 GMT+08:00

查询转码任务

您可根据转码任务ID、状态、页码数、开始和结束时间,查询单个或多个转码任务的执行情况。

在查询到的结果集中,如果不提供页码数和显示条数并且数据大于10条,会默认显示10条数据并进行分页处理。

具体查询条件和查询结果参数请参考查询转码任务接口。

查询单个转码任务

1
2
3
4
5
//按单个TaskId查询任务,TaskId是转码请求响应中返回的任务ID
ListTranscodingTaskRequest req = new ListTranscodingTaskRequest().withTaskId(Collections.singletonList(3273178L));
//发送请求
ListTranscodingTaskResponse listTranscodingTaskResponse = initMpcClient().listTranscodingTask(req);
System.out.println(JsonUtils.toJSON(listTranscodingTaskResponse));

查询多个转码任务

1
2
3
4
5
//按多个TaskId查询任务,TaskId是转码请求响应中返回的任务ID
ListTranscodingTaskRequest req = new ListTranscodingTaskRequest().withTaskId(Arrays.asList(3273178L, 3273179L));
//发送请求
ListTranscodingTaskResponse listTranscodingTaskResponse = initMpcClient().listTranscodingTask(req);
System.out.println(JsonUtils.toJSON(listTranscodingTaskResponse));

根据状态查询

1
2
3
4
5
//按状态查询任务
ListTranscodingTaskRequest req = new ListTranscodingTaskRequest().withStatus("FAILED");
//发送请求
ListTranscodingTaskResponse listTranscodingTaskResponse = initMpcClient().listTranscodingTask(req);
System.out.println(JsonUtils.toJSON(listTranscodingTaskResponse));

根据开始时间和结束时间查询

1
2
3
4
5
//根据转码任务开始和结束时间查询
ListTranscodingTaskRequest req = new ListTranscodingTaskRequest().withStartTime("20210401001517").withEndTime("20210402081517");
//发送请求
ListTranscodingTaskResponse listTranscodingTaskResponse = initMpcClient().listTranscodingTask(req);
System.out.println(JsonUtils.toJSON(listTranscodingTaskResponse));

根据页码查询

1
2
3
4
5
//根据页码和每页条数查询
ListTranscodingTaskRequest req = new ListTranscodingTaskRequest().withPage(0).withSize(4);
//发送请求
ListTranscodingTaskResponse listTranscodingTaskResponse = initMpcClient().listTranscodingTask(req);
System.out.println(JsonUtils.toJSON(listTranscodingTaskResponse));

示例代码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.http.HttpConfig;
import com.huaweicloud.sdk.core.utils.JsonUtils;
import com.huaweicloud.sdk.mpc.v1.MpcClient;
import com.huaweicloud.sdk.mpc.v1.model.ListTranscodingTaskRequest;
import com.huaweicloud.sdk.mpc.v1.model.ListTranscodingTaskResponse;

public class TestListTranscode {
    /**
     * 初始化 MpcClient
     * @return
     */
    public static MpcClient initMpcClient() {
        HttpConfig httpConfig = HttpConfig.getDefaultHttpConfig().withIgnoreSSLVerification(true).withTimeout(3);
        //http代理设置,请根据实际情况设置
        //httpConfig.withProxyHost("xxxxxx").withProxyPort(xxxxxx).withProxyUsername("xxxxxx").
        //        withProxyPassword("xxxxxx");
        //根据实际填写ak,sk,在控制台账号名下“我的凭证 > 访问密钥”上创建和查看您的AK/SK
        
        String ak = System.getenv("SDK_AK");
        String sk = System.getenv("SDK_SK");
        //根据实际填写项目ID,在控制台账号名下“我的凭证 > API凭证”下查看您的项目ID
        String projectId = System.getenv("PROJECT_ID");
        //根据实际填写所需endpoint,这里以“region01”为例
        String endpoint = "https://mpc.region01.myhuaweicloud.com";
        BasicCredentials auth = new BasicCredentials().withAk(ak).withSk(sk).withProjectId(projectId);
        return MpcClient.newBuilder()
                .withHttpConfig(httpConfig)
                .withCredential(auth)
                .withEndpoint(endpoint)
                .build();
    }

    /**
     * 查询转码任务
     */
    public static void main(String[] args) {
        try {
            //按TaskId查询任务,TaskId是转码请求响应中返回的任务ID
            ListTranscodingTaskRequest req = new ListTranscodingTaskRequest().withTaskId(Collections.singletonList(3273178L));
            //发送请求
            ListTranscodingTaskResponse listTranscodingTaskResponse = initMpcClient().listTranscodingTask(req);
            System.out.println(JsonUtils.toJSON(listTranscodingTaskResponse));
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}