Pili Streaming Cloud server-side library for Java
Java
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples
gradle/wrapper
src
.gitignore adjust package path Feb 29, 2016
.travis.yml
LICENSE
README.md
build.gradle
gradle.properties
gradlew
gradlew.bat
mvn_push.gradle
settings.gradle mvn push Jul 1, 2016

README.md

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)
    • 批量查询直播实时信息: hub.batchLiveStatus(streamTitles)
  • Stream
    • 流信息: stream.info()
    • 禁用流: stream.disable() / stream.disable(disabledTill)
    • 解禁流: stream.enable()
    • 查询直播状态: stream.liveStatus()
    • 保存直播回放: stream.save(key, start, end) / stream.save(saveOptions)
    • 保存直播截图: stream.snapshot(snapshotOptions) zzz
    • 更改流的实时转码规格: stream.updateConverts(profiles)
    • 查询直播历史: 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.1.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=
*/

Batch live status

Hub.BatchLiveStatus[] statuses = hub.batchLiveStatus(new String[]{"strm1","strm2"});

Stream

Get stream info

Get the latest stream info

Stream stream = hub.get("streamkey")
stream.disable()
// will get the latest info from server
stream = stream.info()

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}
*/

stream.disable(1488540526L);
stream.info();
/*
after disable: {"Hub":"PiliSDKTest","Key":"streamkey","DisabledTill":1488540526}
*/

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)
/*
recordings/z1.hub1.strm1/0_1488529267.m3u8
*/

Snapshot Stream

Stream.SnapshotOptions opts = new Stream.SnapshotOptions();
opts.fname = "test";
stream.snapshot(opts);

Update converts

String[] profiles = {"480p", "720p"};
stream.updateConverts(profiles);