更新时间:2024-01-31 GMT+08:00

取消转码任务

说明

  • 取消转码任务需要用户提供所要取消任务的taskId。
  • 待取消的taskId只能是正在转码任务队列中排队的转码任务。已开始转码或已完成的转码任务不能取消。
  • 错误处理请参考错误码表

设置取消转码参数

1
2
3
4
5
6
7
//取消任务,TaskId是转码请求响应中返回的任务ID
DeleteTranscodingTaskRequest req = new DeleteTranscodingTaskRequest().withTaskId(3273178);
//发送请求
DeleteTranscodingTaskResponse deleteTranscodingTaskResponse =
        initMpcClient().deleteTranscodingTask(req);
//返回处理消息
System.out.println(JsonUtils.toJSON(deleteTranscodingTaskResponse));

示例代码

 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
49
50
51
52
53
54
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ClientRequestException;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
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.DeleteTranscodingTaskRequest;
import com.huaweicloud.sdk.mpc.v1.model.DeleteTranscodingTaskResponse;
import com.obs.services.internal.ServiceException;

public class TestDeleteTranscode {
    /**
     * 初始化 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是转码请求响应中返回的任务ID
            DeleteTranscodingTaskRequest req = new DeleteTranscodingTaskRequest().withTaskId(3273178);
            //发送请求
            DeleteTranscodingTaskResponse deleteTranscodingTaskResponse =
                    initMpcClient().deleteTranscodingTask(req);
            //返回处理消息
            System.out.println(JsonUtils.toJSON(deleteTranscodingTaskResponse));
        } catch (ClientRequestException | ConnectionException | RequestTimeoutException | ServiceException e) {
            System.out.println(e);
        }
    }
}