全部文档
当前文档

暂无内容

如果没有找到您期望的内容,请尝试其他搜索词

文档中心

SDK for Java 使用指南

最近更新时间:2022-02-18 17:38:13

安装java sdk

###1.git 安装###

git clone https://github.com/KscSDK/ksc-sdk-java.git	

mvn clean install

###2.mvn 中央仓库安装###

设置pom文件即可

###3.工程使用sdk录###

####建议使用Maven构建自己的项目,导入ksc-sdk-java,添加ksc-sdk-java-ket的依赖。

#####新建maven项目

#####进入到pom文件下,进行如下配置

<dependencies>

    <dependency>

        <groupId>com.ksyun</groupId>

        <artifactId>ksc-sdk-java-ket</artifactId>

        <version>0.3.21</version>

    </dependency>

</dependencies>

###4.通过文件配置及管理密钥

#####本地文件配置:

 ~/.aws/credentials on Linux, OS X or unix

C:\Users\USERNAME\.aws\credentials on Windows

#####该文件包含下述内容:

[default]

aws_access_key_id = your_access_key_id

aws_secret_access_key = your_secret_access_key

#####如不通过本地文件读入ak和sk信息,则需要在执行的类文件中增加以下代码:

AWSCredentials credentials = new BasicAWSCredentials(aws_access_key_id, aws_secret_access_key);

##SDK介绍和使用

#####在调用接口前,先初始化 KSCOFFJsonClient,如下用例:

KSCKETJsonClient ksc = new KSCKETJsonClient();

//可传入AWSCredentials参数 如:KSCKETJsonClient ksc = new KSCKETJsonClient(credentials);

ksc.setEndpoint("http://ket.cn-beijing-6.api.ksyun.com/");

字符集:utf-8

##SDK介绍和使用##

##接口目录说明##

##注:接口的传递的参数及返回值请参考《视频云直播转码接入说明》API接口说明##

1.创建和更新模板

  • 接口名: Preset和UpdatePreset
  • 调用方式
PresetRequest presetRequest = new PresetRequest();

String data = PresetSet("preset", 2);

presetRequest.setData(data);

ErrResult presetResult = ksc.Preset(presetRequest);

System.out.println("ErrNum: " + presetResult.getErrNum() + ",ErrMsg: " + presetResult.getErrMsg());

//请求内容生成接口

private static String PresetSet(String preset, int num) throws JSONException {

	int formatSet[] = new int[] { 256, 257, 258, 259 };

	JSONObject data = new JSONObject();

	JSONArray output = new JSONArray();

	JSONArray logo = new JSONArray();

	JSONObject video = new JSONObject();

	data.put("UniqName", "mytest");

	data.put("Preset", preset);

	data.put("Description", "desc:" + preset);

	data.put("App", "live");

	for (int i = 0; i < num; i++) {

		JSONObject output_tmp = new JSONObject();

		JSONObject format = new JSONObject();

		JSONObject _switch = new JSONObject();

		format.put("output_format", formatSet[i]);

		format.put("vbr", 800000);

		_switch.put("sn", 0);

		_switch.put("sm", 0);

		_switch.put("hv", 0);

		output_tmp.put("format", format);

		output_tmp.put("switch", _switch);

		output.put(output_tmp);

	}

	data.put("Output", output);

	video.put("orientationAdapt", 1);

	for (int i = 0; i < num; i++) {

		JSONObject logo_tmp = new JSONObject();

		logo_tmp.put("pic", "/wangshuai9/1.png");

		logo_tmp.put("short_side", 640);

		logo.put(logo_tmp);

	}

	video.put("logo", logo);

	data.put("Video", video);

	return data.toString();

}

2.删除模板

  • 接口名: DelPreset
  • 调用方式
DelPresetRequest delpresetRequest = new DelPresetRequest();

delpresetRequest.setApp("live");

delpresetRequest.setUniqName("mytest");

delpresetRequest.setPreset("preset");

ErrResult delpresetResult = ksc.DelPreset(delpresetRequest);

System.out.println("ErrNum: " + delpresetResult.getErrNum() + ",ErrMsg: " + delpresetResult.getErrMsg());

3.查询模板列表

  • 接口名: GetPresetList
  • 调用方式
GetPresetListRequest getPresetListRequest = new GetPresetListRequest();

getPresetListRequest.setApp("live");

getPresetListRequest.setUniqName("mytest");

GetPresetListResult getpresetlistResult = ksc.GetPresetList(getPresetListRequest);

4.查询模板详情

  • 接口名: GetPresetDetail
  • 调用方式
GetPresetDetailRequest getPresetDetailRequest = new GetPresetDetailRequest();

getPresetDetailRequest.setApp("live");

getPresetDetailRequest.setUniqName("mytest");

getPresetDetailRequest.setPreset("preset");

GetPresetDetailResult getPresetDetailResult = ksc.GetPresetDetail(getPresetDetailRequest);

5.获取任务列表

  • 接口名: GetStreamTranList
  • 调用方式
GetStreamTranListRequest getStreamTranListRequest = new GetStreamTranListRequest();

getStreamTranListRequest.setApp("live");

getStreamTranListRequest.setUniqName("mytest");

GetStreamTranListResult getStreamTranListResult = ksc.GetStreamTranList(getStreamTranListRequest);

6.发起外网拉流

  • 接口名: StartStreamPull
  • 调用方式
StartStreamPullRequest startStreamPullRequest = new StartStreamPullRequest();

String data1 =  StreamPullSet("test123");

startStreamPullRequest.setData(data1);

ErrResult startStreamPullResult = ksc.StartStreamPull(startStreamPullRequest);

System.out.println("ErrNum: " + startStreamPullResult.getErrNum() + ",ErrMsg: " + startStreamPullResult.getErrMsg());

//请求内容接口

private static String StreamPullSet(String StreamID) {

	JSONObject data = new JSONObject();

	data.put("UniqName", "mytest");

	data.put("StreamID", StreamID);

	if (type == 0) {

		data.put("SrcUrl", "test.uplive.ks-cdn.com");

	}

	data.put("App", "live");

	return data.toString();

}

7.停止外网拉流

  • 接口名: StopStreamPull
  • 调用方式
StopStreamPullRequest stopStreamPullRequest = new StopStreamPullRequest();

String data2 =  StreamPullSet("test123");

stopStreamPullRequest.setData(data2);

ErrResult stopStreamPullResult = ksc.StopStreamPull(stopStreamPullRequest);

System.out.println("ErrNum: " + stopStreamPullResult.getErrNum() + ",ErrMsg: " + stopStreamPullResult.getErrMsg());

//请求内容接口

private static String StreamPullSet(String StreamID) {

	JSONObject data = new JSONObject();

	data.put("UniqName", "mytest");

	data.put("StreamID", StreamID);

	if (type == 0) {

		data.put("SrcUrl", "test.uplive.ks-cdn.com");

	}

	data.put("App", "live");

	return data.toString();

}

8.获取配额使用数据

  • 接口名: GetQuotaUsed
  • 调用方式
GetQuotaUsedRequest getQuotaUsedRequest = new GetQuotaUsedRequest();

getQuotaUsedRequest.setUniqName(UniqName);

GetQuotaUsedResult getQuotaUsedResult = ksc.GetQuotaUsed(getQuotaUsedRequest);

System.out.println("ErrNum: " + getQuotaUsedResult.getErrNum() + ",ErrMsg: " + getQuotaUsedResult.getErrMsg());
文档导读
纯净模式常规模式

纯净模式

点击可全屏预览文档内容
文档反馈