全部产品
云市场

音视频播放

更新时间:2018-12-28 19:33:56

初始化客户端

使用前请先初始化客户端,参考 InitVodClient 接口。

获取播放地址

接口参数和返回字段请参考 GetPlayInfo

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "fmt"
  7. )
  8. func MyGetPlayInfo(client *vod.Client, videoId string) (response *vod.GetPlayInfoResponse, err error) {
  9. request := vod.CreateGetPlayInfoRequest()
  10. request.VideoId = videoId
  11. request.AcceptFormat = "JSON"
  12. return client.GetPlayInfo(request)
  13. }
  14. func main() {
  15. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  16. if err != nil {
  17. panic(err)
  18. }
  19. response, err := MyGetPlayInfo(client, "<videoId>")
  20. if err != nil {
  21. panic(err)
  22. }
  23. fmt.Println(response.GetHttpContentString())
  24. playList := response.PlayInfoList.PlayInfo
  25. for _, playInfo := range playList {
  26. fmt.Printf("%s: %s\n", playInfo.Definition, playInfo.PlayURL)
  27. }
  28. }

获取播放凭证

接口参数和返回字段请参考 GetVideoPlayAuth

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "fmt"
  7. )
  8. func MyGetPlayAuth(client *vod.Client, videoId string) (response *vod.GetVideoPlayAuthResponse, err error) {
  9. request := vod.CreateGetVideoPlayAuthRequest()
  10. request.VideoId = videoId
  11. request.AcceptFormat = "JSON"
  12. return client.GetVideoPlayAuth(request)
  13. }
  14. func main() {
  15. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  16. if err != nil {
  17. panic(err)
  18. }
  19. response, err := MyGetPlayAuth(client, "<videoId>")
  20. if err != nil {
  21. panic(err)
  22. }
  23. fmt.Println(response.GetHttpContentString())
  24. fmt.Printf("%s: %s\n", response.VideoMeta, response.PlayAuth)
  25. }