- URL
- RTMP推流地址: rtmp_publish_url(domain, hub, stream_key, mac, expire_after_seconds)
- RTMP直播地址: rtmp_play_url(domain, hub, stream_key)
- HLS直播地址: hls_play_url(domain, hub, stream_key)
- HDL直播地址: hdl_play_url(domain, hub, stream_key)
- 截图直播地址: snapshot_play_url(domain, hub, stream_key)
- Hub
- 创建流: hub.create(stream_key)
- 获得流: hub.stream(stream_key)
- 列出流: hub.list(...)
- 列出正在直播的流: hub.list_live(...)
- Stream
- 流信息: stream.info()
- 禁用流: stream.disable()
- 启用流: stream.enable()
- 查询直播状态: stream.live_status()
- 保存直播回放: stream.save(...)
- 查询直播历史: stream.history_activity(...)
Add this line to your application's Gemfile:
gem 'piliv2'
And then execute:
$ bundle
Or install it yourself as:
$ gem install piliv2
require "piliv2"
access_key = "<QINIU ACCESS KEY>" # 替换成自己 Qiniu 账号的 AccessKey.
secret_key = "<QINIU SECRET KEY>" # 替换成自己 Qiniu 账号的 SecretKey.
hub_name = "<PILI HUB NAME>" # Hub 必须事先存在.
mac = Pili::Mac.new(access_key, secret_key)
client = Pili::Client.new(mac)
hub = client.hub(hub_name)
url = Pili.rtmp_publish_url("publish-rtmp.test.com", "PiliSDKTest", "streamkey", mac, 60)
puts(url)
# rtmp://publish-rtmp.test.com/PiliSDKTest/streamkey?e=1463023142&token=7O7hf7Ld1RrC_fpZdFvU8aCgOPuhw2K4eapYOdII:-5IVlpFNNGJHwv-2qKwVIakC0ME=
url = Pili.rtmp_play_url("live-rtmp.test.com", "PiliSDKTest", "streamkey")
puts(url)
# rtmp://live-rtmp.test.com/PiliSDKTest/streamkey
url = Pili.hls_play_url("live-hls.test.com", "PiliSDKTest", "streamkey")
puts(url)
# http://live-hls.test.com/PiliSDKTest/streamkey.m3u8
url = Pili.hdl_play_url("live-hdl.test.com", "PiliSDKTest", "streamkey")
puts(url)
# http://live-hdl.test.com/PiliSDKTest/streamkey.flv
url = Pili.snapshot_play_url("live-snapshot.test.com", "PiliSDKTest", "streamkey")
puts(url)
# http://live-snapshot.test.com/PiliSDKTest/streamkey.jpg
mac = Pili::Mac.new(access_key, secret_key)
client = Pili::Client.new(mac)
hub = client.hub("PiliSDKTest")
stream = hub.create("streamkey")
puts(stream.info.to_json)
# {"hub":"PiliSDKTest","key":"streamkey","disabled":false}
stream = hub.stream("streamkey")
puts(stream.info.to_json)
# {"hub":"PiliSDKTest","key":"streamkey","disabled":false}
keys, marker = hub.list(:prefix=>"str", :limit=>10)
puts keys.to_s, marker
# [<keys...>], <marker>
keys, marker = hub.list_live(:prefix=>"str", :limit=>10)
puts keys.to_s, marker
# [<keys...>], <marker>
stream = hub.stream(key)
puts(stream.info.to_json)
# {"hub": "PiliSDKTest", "key": "streamkey", "disabled": false}
stream = hub.stream("streamkey")
puts("before disable: #{stream.info.to_json}")
stream.disable()
stream = hub.stream("streamkey")
puts("after disable: #{stream.info.to_json}")
# before disable: {"hub":"PiliSDKTest","key":"streamkey","disabled":false}
# after disable: {"hub":"PiliSDKTest","key":"streamkey","disabled":true}
stream = hub.stream("streamkey")
puts("before enable: #{stream.info.to_json}")
stream.enable()
stream = hub.get("streamkey")
puts("after enable: #{stream.info.to_json}")
# before disable: {"hub":"PiliSDKTest","key":"streamkey","disabled":true}
# after disable: {"hub":"PiliSDKTest","key":"streamkey","disabled":false}
status = stream.live_status()
puts(status.to_json)
# {"startAt":1463022236,"clientIP":"222.73.202.226","bps":248,"fps":{"audio":45,"vedio":28,"data":0}}
activity = stream.history_activity()
puts(activity.to_json)
# [{"start":1463022236,"end":1463022518}]
fname = stream.save()
puts(fname)
# recordings/z1.PiliSDKTest.streamkey/1463156847_1463157463.m3u8