- 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)
The project is built with java 1.7.
Firstly, make sure you have gradle on your machine.
Then all you have to do is just
gradle build
okhttp, okio, Gson
compile 'com.qiniu.pili:pili-sdk-java:2.0.0'
Client cli = new Client(accessKey,secretKey);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=
*/String url = cli.RTMPPlayURL("live-rtmp.test.com", "PiliSDKTest", "streamkey");
/*
rtmp://live-rtmp.test.com/PiliSDKTest/streamkey
*/url = cli.HLSPlayURL("live-hls.test.com", "PiliSDKTest", "streamkey");
/*
http://live-hls.test.com/PiliSDKTest/streamkey.m3u8
*/url = cli.HDLPlayURL("live-hdl.test.com", "PiliSDKTest", "streamkey");
/*
http://live-hdl.test.com/PiliSDKTest/streamkey.flv
*/url = cli.SnapshotPlayURL("live-snapshot.test.com", "PiliSDKTest", "streamkey");
/*
http://live-snapshot.test.com/PiliSDKTest/streamkey.jpg
*/public static void main(String args[]) {
Client cli = new Client(accessKey, secretKey);
Hub hub = cli.newHub("PiliSDKTest");
// ...
}Stream stream = hub.create("streamkey")
System.out.println(stream.toJson());
/*
{"Hub":"PiliSDKTest","Key":"streamkey","DisabledTill":0}
*/Stream stream = hub.get("streamkey")
System.out.println(stream.toJson())
/*
{"Hub":"PiliSDKTest","Key":"streamkey","DisabledTill":0}
*/Hub.ListRet listRet = hub.list("str", 10, "")
/*
keys=[streamkey] marker=
*/Hub.ListRet listRet = hub.listLive("str", 10, "")
/*
keys=[] marker=
*/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 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}
*/Stream.LiveStatus status = stream.liveStatus();
/*
{"startAt":1463022236,"clientIP":"222.73.202.226","bps":248,"fps":{"audio":45,"vedio":28,"data":0}}
*/Stream.Record[] records = stream.historyRecord(0, 0)
/*
[{1463022236,1463022518}]
*/String fname = stream.save(0, 0)
/*
FtVdro8JYNwq4uVFALsKGWDRVaiN
*/