SDK for Java 使用指南

最近更新时间:2020-09-23 14:28:12

查看PDF

安装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.9</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.发起轮播

  • 接口名: StartLoop
  • 调用方式
StartLoopRequest startLoopRequest = new StartLoopRequest();

String startLoopData = StartLoopSet();

startLoopRequest.setData(startLoopData);

StartLoopResult startLoopResult = ksc.StartLoop(startLoopRequest);

System.out.println(startLoopResult.getList().get(0).getTaskID());

//请求内容接口

private static String StartLoopSet() {

	JSONObject data = new JSONObject();

	JSONArray srcInfo = new JSONArray();

	data.put("PubDomain", "videoqa.uplive.ks-cdn.com");

	data.put("UniqName", UniqName);

	data.put("Preset", "looppreset");

	data.put("StreamID", "java_sdk_1234");

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

	data.put("DurationHour", 168);

	JSONObject tmp = new JSONObject();

	tmp.put("Path", "http://ks3-cn-beijing-internal.ksyun.com/qa-screenshot/offline_source_file/offline_mkv.mkv");

	tmp.put("Index", 0);

	srcInfo.put(tmp);

	data.put("SrcInfo", srcInfo);

	return data.toString();

}

9.停止轮播

  • 接口名: StopLoop
  • 调用方式
StopLoopRequest stopLoopRequest = new StopLoopRequest();

String stopLoopData = StopLoopSet();

stopLoopRequest.setData(stopLoopData);

ErrResult stopLoopResult = ksc.StopLoop(stopLoopRequest);

//请求内容接口

private static String StopLoopSet() {

	JSONObject data = new JSONObject();

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

	data.put("UniqName", UniqName);

	data.put("StreamID", "java_sdk_1234");

	return data.toString();

}

10.更新轮播时长

  • 接口名: UpdateLoop
  • 调用方式
UpdateLoopRequest updateLoopRequest = new UpdateLoopRequest();

String updateLoopData = UpdateLoopSet();

updateLoopRequest.setData(updateLoopData);

ErrResult updateLoop = ksc.UpdateLoop(updateLoopRequest);

System.out.println(updateLoop.getErrMsg());

//请求内容接口

private static String UpdateLoopSet() {

	JSONObject data = new JSONObject();

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

	data.put("UniqName", UniqName);

	data.put("StreamID", "java_sdk_1234");

	data.put("DurationHour", 10);

	return data.toString();

}

11.获取轮播列表

  • 接口名: GetLoopList
  • 调用方式
GetLoopListRequest getLoopListRequest = new GetLoopListRequest();

getLoopListRequest.setApp("live");

getLoopListRequest.setUniqName(UniqName);

GetLoopListResult getLoopListResult = ksc.GetLoopList(getLoopListRequest);

System.out.println(getLoopListResult.getList().get(0).getTaskID());

12.获取配额使用数据

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

getQuotaUsedRequest.setUniqName(UniqName);

GetQuotaUsedResult getQuotaUsedResult = ksc.GetQuotaUsed(getQuotaUsedRequest);

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

13.创建选流任务

  • 接口名:CreateDirectorTask
  • 调用方式
CreateDirectorTaskRequest createDirectorTaskRequest = new CreateDirectorTaskRequest();

createDirectorTaskRequest.setData(DirectorTaskSet());

ErrResult createDirectorTaskResult = ksc.CreateDirectorTask(createDirectorTaskRequest);

System.out.println(createDirectorTaskResult.getTaskID());

private static String DirectorTaskSet(){

	JSONObject data = new JSONObject();

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

	data.put("UniqName", UniqName);

	JSONArray SrcInfo = new JSONArray();

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

		JSONObject info = new JSONObject();

		info.put("SrcUrl","rtmp://host/app/outernetStreamForSwitch");

		info.put("Index",i);

		SrcInfo.put(info);

	}		

	data.put("SrcInfo", SrcInfo);

	return data.toString();

}

14.更新选流任务

  • 接口名:UpdateDirectorTask
  • 调用方式
UpdateDirectorTaskRequest updateDirectorTaskRequest = new UpdateDirectorTaskRequest();

updateDirectorTaskRequest.setData(DirectorTaskSet());

ErrResult updateDirectorTaskResult = ksc.UpdateDirectorTask(updateDirectorTaskRequest);

System.out.println(updateDirectorTaskResult.getErrNum());

private static String DirectorTaskSet(){

	JSONObject data = new JSONObject();

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

	data.put("UniqName", UniqName);

	JSONArray SrcInfo = new JSONArray();

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

		JSONObject info = new JSONObject();

		info.put("SrcUrl","rtmp://host/app/outernetStreamForSwitch");

		info.put("Index",i);

		SrcInfo.put(info);

	}		

	data.put("SrcInfo", SrcInfo);

	return data.toString();

}

15.查询选流任务

  • 接口名:QueryDirectorTask
  • 调用方式
QueryDirectorTaskRequest queryDirectorTaskRequest = new QueryDirectorTaskRequest();

queryDirectorTaskRequest.setApp("live");

queryDirectorTaskRequest.setUniqName(UniqName);

QueryDirectorTaskResult queryDirectorTaskResult = ksc.QueryDirectorTask(queryDirectorTaskRequest);

System.out.println(queryDirectorTaskResult.getErrNum());

16.删除选流任务

  • 接口名:DelDirectorTask
  • 调用方式
DelDirectorTaskRequest delDirectorTaskRequest = new DelDirectorTaskRequest();

delDirectorTaskRequest.setApp("live");

delDirectorTaskRequest.setUniqName(UniqName);

ErrResult delDirectorTaskResult = ksc.DelDirectorTask(delDirectorTaskRequest);

System.out.println(delDirectorTaskResult.getErrNum());

文档内容是否对您有帮助?

根本没帮助
文档较差
文档一般
文档不错
文档很好

在文档使用中是否遇到以下问题

  • 内容不全,不深入
  • 内容更新不及时
  • 描述不清晰,比较混乱
  • 系统或功能太复杂,缺乏足够的引导
  • 内容冗长

更多建议

0/200

评价建议不能为空

提交成功!

非常感谢您的反馈,我们会继续努力做到更好!

问题反馈