本示例介绍使用Alibaba Cloud SDK for Java调用AddCasterVideoResource接口添加视频源。

前提条件

请在pom.xml文件中增加以下依赖,准确的SDK版本号,参见阿里云开发工具包(SDK)

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>java.demo</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <!-- https://mvnrepository.com/artifact/com.aliyun/aliyun-java-sdk-core -->
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-core</artifactId>
            <version>4.4.3</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.aliyun/aliyun-java-sdk-live -->
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-live</artifactId>
            <version>3.7.5</version>
        </dependency>
    </dependencies>
</project>

示例代码

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.live.model.v20161101.AddCasterVideoResourceRequest;
import com.aliyuncs.live.model.v20161101.AddCasterVideoResourceResponse;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;

/**
 * 添加视频源,视频源数量受限于导播台输入路数。
 */
public class TestAddCasterVideoResource {

    public static void main(String[] args) {
        DefaultProfile profile = DefaultProfile.getProfile(
                "<your-region-id>", // 地域ID,可以通过接口 DescribeRegions 查看可用的地域ID。
                "<your-access-key-id>", // 您的AccessKey ID
                "<your-access-key-secret>"); // 您的AccessKey Secret
        IAcsClient client = new DefaultAcsClient(profile);

        AddCasterVideoResourceRequest request = new AddCasterVideoResourceRequest();
        // 视频源名称
        request.setResourceName("yourResourceName");
        // 导播台ID
        request.setCasterId("yourCasterId");
        // 直播流地址,视频源类型为直播流时必填
        request.setLiveStreamUrl("");
        // 用于指定视频源位置,定义布局画面的引用编号,每个位置至多设置一个资源,数量受限于导播台创建时的输入路数,格式需符合“RV01...RV12”
        // request.setLocationId("RV01");

        try {
            // 发起请求并获取返回值
            AddCasterVideoResourceResponse response = client.getAcsResponse(request);
            // 处理业务逻辑
            System.out.println(new Gson().toJson(response));
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            System.out.println("ErrCode:" + e.getErrCode());
            System.out.println("ErrMsg:" + e.getErrMsg());
            System.out.println("RequestId:" + e.getRequestId());
        }
    }
}