- 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)
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.1.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=
*/
Hub.BatchLiveStatus[] statuses = hub.batchLiveStatus(new String[]{"strm1","strm2"});
Get the latest stream info
Stream stream = hub.get("streamkey")
stream.disable()
// will get the latest info from server
stream = stream.info()
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}
*/
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)
/*
recordings/z1.hub1.strm1/0_1488529267.m3u8
*/
Stream.SnapshotOptions opts = new Stream.SnapshotOptions();
opts.fname = "test";
stream.snapshot(opts);
String[] profiles = {"480p", "720p"};
stream.updateConverts(profiles);