代码拉取完成,页面将自动刷新
阿里云直播 golang SDK
package main
import (
"github.com/BPing/aliyun-live-go-sdk/aliyun"
"github.com/BPing/aliyun-live-go-sdk/device/live"
"github.com/BPing/aliyun-live-go-sdk/util"
"time"
"fmt"
)
const (
AccessKeyId = "<Yours' Id>"
AccessKeySecret = "<...>"
)
func main() {
cert := aliyun.NewCredentials(AccessKeyId, AccessKeySecret)
live := live.NewLive(cert, "<Yours' CDN>", "app-name",nil).SetDebug(true)
resp := make(map[string]interface{})
live.StreamsPublishList(time.Now().Add(-time.Hour * 12), time.Now(), &resp)
fmt.Println(resp)
}
go get:
go get github.com/BPing/aliyun-live-go-sdk
(v0.5,v0.5-)
方法名以"WithApp"结尾代表可以更改请求中 "应用名字(AppName)",
否则按默认的(初始化时设置的AppName)。
如果为空,代表忽略参数AppName
(v0.6+)
移除以"WithApp"为后缀方法。
cert := client.NewCredentials(AccessKeyId, AccessKeySecret)
liveM := live.NewLive(cert, DomainName, AppName, nil).SetDebug(true)
resp := make(map[string]interface{})
liveM.StreamsPublishList(time.Now().Add(-time.Hour * 12), time.Now(), &resp)
fmt.Println(resp)
// @appname 应用名 为空时,忽略此参数
resp := make(map[string]interface{})
liveM.StreamsPublishListWithApp(AppName,time.Now().Add(-time.Hour * 12), time.Now(), &resp)
fmt.Println(resp)
resp = make(map[string]interface{})
err = liveM.StreamsBlockList(&resp)
fmt.Println(err, resp)
resp1 := live.OnlineInfoResponse{}
err := liveM.StreamOnlineUserNum("video-name", &resp1)
fmt.Println(err, resp1)
// @appname 应用名 为空时,忽略此参数 (v0.5,v0.5-)
resp1 := live.OnlineInfoResponse{}
err := liveM.StreamOnlineUserNumWithApp(AppName,"video-name", &resp1)
fmt.Println(err, resp1)
resp = make(map[string]interface{})
err = liveM.StreamsControlHistory(time.Now().Add(-time.Hour * 12), time.Now(), &resp)
// (v0.5,v0.5-)
//err = liveM.StreamsControlHistoryWithApp(AppName,time.Now().Add(-time.Hour * 12), time.Now(), &resp)
fmt.Println(err, resp)
resp = make(map[string]interface{})
err = liveM.ForbidLiveStreamWithPublisher("video-name", nil, &resp)
fmt.Println(err, resp)
resp = make(map[string]interface{})
err = liveM.ResumeLiveStreamWithPublisher("video-name", &resp)
fmt.Println(err, resp)
oss := live.OssInfo{
OssBucket: OssBucket,
OssEndpoint: OssEndpoint,
OssObject: OssObject,
OssObjectPrefix: OssObjectPrefix,
}
config:=live.SnapshotConfig{
OssInfo:oss,
TimeInterval : 5,
OverwriteOssObject : "{AppName}/{StreamName}.jpg",
}
resp := make(map[string]interface{})
err:=liveM.AddLiveAppSnapshotConfig(config,&resp)
fmt.Println(err, resp)
config.SequenceOssObject="{AppName}/{StreamName}.jpg"
resp = make(map[string]interface{})
err=liveM.UpdateLiveAppSnapshotConfig(config,&resp)
fmt.Println(err, resp)
param:=live.LiveSnapshotParam{
PageNum:1,
PageSize:10,
Order:"asc",
}
resp = make(map[string]interface{})
err=liveM.LiveSnapshotConfig(param,&resp)
fmt.Println(err, resp)
resp = make(map[string]interface{})
err=liveM.LiveStreamSnapshotInfo("test-video-name1",time.Now().Add(-time.Hour*24*20), time.Now(),10,&resp)
fmt.Println(err, resp)
resp = make(map[string]interface{})
err=liveM.DeleteLiveAppSnapshotConfig(&resp)
fmt.Println(err, resp)
resp := make(map[string]interface{})
err:=liveM.AddLiveStreamTranscode("a","no","no",&resp)
fmt.Println(err, resp)
resp = make(map[string]interface{})
err=liveM.LiveStreamTranscodeInfo(&resp)
fmt.Println(err, resp))
resp = make(map[string]interface{})
err=liveM.DeleteLiveStreamTranscode("a",&resp)
fmt.Println(err, resp)
err=liveM.StartMixStreamsService(...)
err=liveM.StopMixStreamsService(...)
err=liveM.AddLivePullStreamInfoConfig(...)
err=liveM.DeleteLivePullStreamInfoConfig(...)
err=liveM.DescribeLivePullStreamConfig(...)
err=liveM.AddLiveMixConfig(...)
err=liveM.DescribeLiveMixConfig(...)
err=liveM.DeleteLiveMixConfig(...)
err=liveM.StartMultipleStreamMixService(...)
err=liveM.StopMultipleStreamMixService(...)
err=liveM.AddMultipleStreamMixService(...)
err=liveM.RemoveMultipleStreamMixService(...)
err=liveM.AddLiveMixNotifyConfig(...)
err=liveM.DescribeLiveMixNotifyConfig(...)
err=liveM.DeleteLiveMixNotifyConfig(...)
err=liveM.UpdateLiveMixNotifyConfig(...)
err=liveM.SetStreamsNotifyUrlConfig(...)
err=liveM.DeleteLiveStreamsNotifyUrlConfig(...)
err=liveM.StreamsNotifyUrlConfig(...)
err=liveM.AddLiveRecordVodConfig(...)
err=liveM.DeleteLiveRecordVodConfig(...)
err=liveM.DescribeLiveRecordVodConfigs(...)
err=liveM.DescribeLiveDomainBpsData(...)
err=liveM.DescribeLiveDomainRecordData(...)
err=liveM.DescribeLiveDomainSnapshotData(...)
err=liveM.DescribeLiveDomainTrafficData(...)
err=liveM.DescribeLiveDomainTranscodeData(...)
err=liveM.DescribeLiveStreamHistoryUserNum(...)
err=liveM.DescribeLiveSnapshotDetectPornConfig(...)
err=liveM.AddLiveSnapshotDetectPornConfig(...)
err=liveM.UpdateLiveSnapshotDetectPornConfig(...)
err=liveM.DeleteLiveSnapshotDetectPornConfig(...)
err=liveM.DescribeLiveDetectNotifyConfig(...)
err=liveM.AddLiveDetectNotifyConfig(...)
err=liveM.UpdateLiveDetectNotifyConfig(...)
err=liveM.DeleteLiveDetectNotifyConfig(...)
//如果 streamCert 为空的话,则代表不开启直播流鉴权
cert := client.NewCredentials(AccessKeyId, AccessKeySecret)
streamCert := live.NewStreamCredentials(PrivateKey, live.DefaultStreamTimeout)
liveM := live.NewLive(cert, DomainName, AppName, streamCert)
// GetStream 获取直播流
// @describe 每一次都生成新的流实例,不检查流名的唯一性,并且同一个名字会生成不同的实例的,
// 所以,使用时候,请自行确保流名的唯一性
stream := liveM.GetStream("video-name")
// RTMP 推流地址
// 如果开启了直播流鉴权,签名失效后,会重新生成新的有效的推流地址
stream.RtmpPublishUrl()
url:=stream.RtmpLiveUrls()
url:=stream.HlsLiveUrls()
url:=stream.HttpFlvLiveUrls()
num:=stream.OnlineUserNum()
isOnline:=stream.Online()
isBlocked:=stream.Blocked()
// type FrameRateAndBitRateInfos struct {
// FrameRateAndBitRateInfo []FrameRateAndBitRateInfo
//}
//
//// 各直播流的帧率/码率信息
//type FrameRateAndBitRateInfo struct {
// StreamUrl string // 直播流的URL
// VideoFrameRate int // 直播流的视频帧率
// AudioFrameRate int // 直播流的音频帧率
// BitRate int // 直播流的码率
//}
frameRateAndBitRateInfo,err:=stream.FrameRateAndBitRateData()
// 查询截图信息
// type StreamSnapshotInfoResponse struct {
// client.Response
// LiveStreamSnapshotInfoList struct {
// StreamSnapshotInfo []StreamSnapshotInfo `json:"StreamSnapshotInfo" xml:"StreamSnapshotInfo"`
// } `json:"LiveStreamSnapshotInfoList" xml:"LiveStreamSnapshotInfoList"` //截图内容列表,没有则返回空数组
// NextStartTime string //
// }
streamSnapshotInfo,err:=stream.SnapshotInfo(time.Now().Add(-time.Hour * 12), time.Now(), 10)
github.com/BPing/go-toolkit/http-client
采用 Apache License, Version 2.0许可证授权原则。
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型