All Products
Search
Document Center

Audio and video playback

Last Updated: Jul 11, 2019

Initialize a client

Initialize a client before using the SDK. For more information, see InitVodClient.

Obtain the audio or video playback URL

For more information about the request and response parameters, see GetPlayInfo.

package main

import (
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
    "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
)

func MyGetPlayInfo(client *vod.Client, videoId string) (response *vod.GetPlayInfoResponse, err error) {
    request := vod.CreateGetPlayInfoRequest()
    request.VideoId = videoId
    request.AcceptFormat = "JSON"

    return client.GetPlayInfo(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>") 
    if err ! = nil {
        panic(err)
    }

    response, err := MyGetPlayInfo(client, "<videoId>")
    if err ! = nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    playList := response.PlayInfoList.PlayInfo
    for _, playInfo := range playList {
        fmt.Printf("%s: %s\n", playInfo.Definition, playInfo.PlayURL)
    }
}

Obtain the video playback credential

For more information about the request and response parameters, see GetVideoPlayAuth.

package main

import (
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
    "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
)

func MyGetPlayAuth(client *vod.Client, videoId string) (response *vod.GetVideoPlayAuthResponse, err error) {
    request := vod.CreateGetVideoPlayAuthRequest()
    request.VideoId = videoId
    request.AcceptFormat = "JSON"

    return client.GetVideoPlayAuth(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err ! = nil {
        panic(err)
    }

    response, err := MyGetPlayAuth(client, "<videoId>") 
    if err ! = nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Printf("%s: %s\n", response.VideoMeta, response.PlayAuth)
}