Skip to content

fayjack/pili-sdk-java

 
 

Repository files navigation

Pili Streaming Cloud Server-Side Library For JAVA

Features

  • URL
    • RTMP推流地址: client.RTMPPublishURL(domain, hub, streamKey, expireAfterDays)
    • RTMP直播地址: RTMPPlayURL(domain, hub, streamKey)
    • HLS直播地址: HLSPlayURL(domain, hub, streamKey)
    • HDL直播地址: HDLPlayURL(domain, hub, streamKey)
    • 截图直播地址: SnapshotPlayURL(domain, hub, streamKey)
  • Hub
    • 创建流: hub.create(streamKey)
    • 查询流: hub.get(streamKey)
    • 列出流: hub.list(prefix, limit, marker)
    • 列出正在直播的流: hub.listLive(prefix, limit, marker)
  • Stream
    • 禁用流: stream.disable()
    • 启用流: stream.enable()
    • 查询直播状态: stream.liveStatus()
    • 保存直播回放: stream.save(key, start, end)
    • 查询直播历史: stream.historyRecord(start, end)

Contents

Java version

The project is built with java 1.7.

Compile JAR

Firstly, make sure you have gradle on your machine.

Then all you have to do is just

gradle build

Dependencies

okhttp, okio, Gson

Install via gradle

compile 'com.qiniu.pili:pili-sdk-java:2.0.0'

Usage

Init

Client cli = new Client(accessKey,secretKey);

URL

Generate RTMP publish URL

String url = cli.RTMPPublishURL("publish-rtmp.test.com", "PiliSDKTest", "streamkey", 60);
/*
rtmp://publish-rtmp.test.com/PiliSDKTest/streamkey?e=1463023142&token=7O7hf7Ld1RrC_fpZdFvU8aCgOPuhw2K4eapYOdII:-5IVlpFNNGJHwv-2qKwVIakC0ME=
*/

Generate RTMP play URL

String url = cli.RTMPPlayURL("live-rtmp.test.com", "PiliSDKTest", "streamkey");
/*
rtmp://live-rtmp.test.com/PiliSDKTest/streamkey
*/

Generate HLS play URL

url = cli.HLSPlayURL("live-hls.test.com", "PiliSDKTest", "streamkey");
/*
http://live-hls.test.com/PiliSDKTest/streamkey.m3u8
*/

Generate HDL play URL

url = cli.HDLPlayURL("live-hdl.test.com", "PiliSDKTest", "streamkey");
/*
http://live-hdl.test.com/PiliSDKTest/streamkey.flv
*/

Generate Snapshot play URL

url = cli.SnapshotPlayURL("live-snapshot.test.com", "PiliSDKTest", "streamkey");
/*
http://live-snapshot.test.com/PiliSDKTest/streamkey.jpg
*/

Hub

Instantiate a Pili Hub object

public static void main(String args[]) { 
	Client cli = new Client(accessKey, secretKey);
	Hub hub = cli.newHub("PiliSDKTest");
	// ...
}

Create a new Stream

Stream stream = hub.create("streamkey")
System.out.println(stream.toJson());
/*
{"Hub":"PiliSDKTest","Key":"streamkey","DisabledTill":0}
*/

Get a Stream

Stream stream = hub.get("streamkey")
System.out.println(stream.toJson())
/*
{"Hub":"PiliSDKTest","Key":"streamkey","DisabledTill":0}
*/

List Streams

Hub.ListRet listRet = hub.list("str", 10, "")
/*
keys=[streamkey] marker=
*/

List live Streams

Hub.ListRet listRet = hub.listLive("str", 10, "")
/*
keys=[] marker=
*/

Stream

Disable a Stream

Stream stream = hub.get("streamkey")
stream.disable()
stream = hub.get("streamkey")
/*
before disable: {"Hub":"PiliSDKTest","Key":"streamkey","DisabledTill":0}
after disable: {"Hub":"PiliSDKTest","Key":"streamkey","DisabledTill":-1}
*/

Enable a Stream

Stream stream = hub.get("streamkey")
stream.enable()
stream = hub.get("streamkey")
/*
before disable: {"Hub":"PiliSDKTest","Key":"streamkey","DisabledTill":-1}
after disable: {"Hub":"PiliSDKTest","Key":"streamkey","DisabledTill":0}
*/

Get Stream live status

Stream.LiveStatus status = stream.liveStatus();
/*
{"startAt":1463022236,"clientIP":"222.73.202.226","bps":248,"fps":{"audio":45,"vedio":28,"data":0}}
*/

Get Stream history record

Stream.Record[] records = stream.historyRecord(0, 0)
/*
[{1463022236,1463022518}]
*/

Save Stream live playback

String fname = stream.save(0, 0)
/*
FtVdro8JYNwq4uVFALsKGWDRVaiN
*/

About

Pili Streaming Cloud server-side library for Java

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%