最近更新时间:2024.03.06 20:04:50
首次发布时间:2021.02.23 10:42:41
本文为您提供了服务端 Go SDK 的媒资播放模块相关的 API 调用示例。主要包含:签发 PlayAuthToken、获取播放地址、签发私有 DRM 加密 AuthToken 等。
使用前请先完成初始化,参考初始化。
由 App/Web Server 持有的 AK/SK 在本地签出,不依赖外网。若希望同时生成多个PlayAuthToken
,您可以循环调用生成方法。PlayAuthToken
用于客户端播放,详见客户端播放。
package vod import ( "encoding/json" "fmt" "testing" "time" "github.com/volcengine/volc-sdk-golang/service/vod" "github.com/volcengine/volc-sdk-golang/service/vod/models/request" ) func TestVod_GetPlayAuthToken(t *testing.T) { vid := "your vid" tokenExpireTime := 600 // Token Expire Duration(s) instance := vod.NewInstance() //instance.SetCredential(base.Credentials{ // AccessKeyID: "your ak", // SecretAccessKey: "your sk", //}) // or set ak and ak as follow //instance.SetAccessKey("") //instance.SetSecretKey("") query := &request.VodGetPlayInfoRequest{ Vid: vid, Format: "mp4", Definition: "360p", FileType: "video", LogoType: "", Ssl: "1", NeedThumbs: "0", NeedBarrageMask: "0", PlayConfig: "{\"PlayDomain\":\"zjh.baidu.com.vod.msadhbui21.com\"}", } newToken, _ := instance.GetPlayAuthToken(query, tokenExpireTime) fmt.Println(newToken) }
接口请求参数和返回参数详见 OpenAPI:获取播放地址。
package vod import ( "fmt" "testing" "github.com/volcengine/volc-sdk-golang/base" "github.com/volcengine/volc-sdk-golang/service/vod" "github.com/volcengine/volc-sdk-golang/service/vod/models/request" ) func Test_GetPlayInfo(t *testing.T) { instance := vod.NewInstance() instance.SetCredential(base.Credentials{ AccessKeyID: "your ak", SecretAccessKey: "your sk", }) query := &request.VodGetPlayInfoRequest{ Vid: "your Vid", Format: "your Format", Codec: "your Codec", Definition: "your Definition", FileType: "your FileType", LogoType: "your LogoType", Base64: "your Base64", Ssl: "your Ssl", NeedThumbs: "your NeedThumbs", NeedBarrageMask: "your NeedBarrageMask", CdnType: "your CdnType", UnionInfo: "your UnionInfo", HDRDefinition: "your HDRDefinition", PlayScene: "your PlayScene", DrmExpireTimestamp: "your DrmExpireTimestamp", Quality: "your Quality", PlayConfig: "your PlayConfig", NeedOriginal: "your NeedOriginal", ForceExpire: "your ForceExpire", } resp, status, err := instance.GetPlayInfo(query) fmt.Println(status) fmt.Println(err) fmt.Println(resp.String()) }
由 App/Web Server 持有的 AK/SK 在本地签出,不依赖外网。若希望同时生成多个PrivateDrmAuthToken
,您可以循环调用生成方法。PrivateDrmAuthToken
用于 Web 客户端播放视频点播自研 DRM 加密音视频,详见客户端播放。
说明
在 Web 端播放时,调用 GetPrivateDrmAuthToken
生成方法,需要指定参数 DrmType
取值为 webdevice
。
package vod import ( "encoding/json" "fmt" "testing" "time" "github.com/volcengine/volc-sdk-golang/service/vod" "github.com/volcengine/volc-sdk-golang/service/vod/models/request" ) func TestVod_GetPrivateDrmAuthToken(t *testing.T) { instance := vod.NewInstance() //instance.SetCredential(base.Credentials{ // AccessKeyID: "your ak", // SecretAccessKey: "your sk", //}) // or set ak and ak as follow //instance.SetAccessKey("") //instance.SetSecretKey("") query := &request.VodGetPrivateDrmPlayAuthRequest{ Vid: "your vid", DrmType: "your drmType", PlayAuthIds: "your playAuthIds", UnionInfo: "your unionInfo", } tokenExpireTime := 6000000 // Token Expire Duration(s) newToken, _ := instance.GetPrivateDrmAuthToken(query, tokenExpireTime) fmt.Println(newToken) }
由 App/Web Server 持有的 AK/SK 在本地签出,不依赖外网。若希望同时生成多个 Sha1HlsDrmAuthToken,您可以循环调用生成方法。Sha1HlsDrmAuthToken 用于 Web 客户端播放 HLS 加密音视频,详见客户端播放。
package vod import ( "encoding/json" "fmt" "testing" "time" "github.com/volcengine/volc-sdk-golang/service/vod" "github.com/volcengine/volc-sdk-golang/service/vod/models/request" ) func TestVod_GetSha1HlsDrmAuthToken(t *testing.T) { instance := vod.NewInstance() instance.SetCredential(base.Credentials{ AccessKeyID: "your ak", SecretAccessKey: "your sk", }) // or set ak and ak as follow //instance.SetAccessKey("your ak") //instance.SetSecretKey("your sk") expireDuration := int64(6000000) //change to your expire duration (s), no default duration token, _ := instance.CreateSha1HlsDrmAuthToken(expireDuration) fmt.Println(token) }