All Products
Search
Document Center

Video playback

Last Updated: Jul 14, 2021

This topic provides examples on how to use the API operations of the video playback module. The API operations are encapsulated in ApsaraVideo VOD SDK for Python. You can call the API operations to query playback URLs and playback credentials.

Initialize a client

Before you can use the SDK, initialize a client. For more information, see Initialization.

Query a playback URL

You can call the GetPlayInfo operation to query a playback URL.

For more information about the request and response parameters of this operation, see GetPlayInfo. Example:

from aliyunsdkvod.request.v20170321 import GetPlayInfoRequest
def get_play_info(clt, videoId):
    request = GetPlayInfoRequest.GetPlayInfoRequest()
    request.set_accept_format('JSON')
    request.set_VideoId(videoId)
    request.set_AuthTimeout(3600*5)
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    playInfo = get_play_info(clt, '<videoId>')
    print(json.dumps(playInfo, ensure_ascii=False, indent=4))

except Exception as e:
    print(e)
    print(traceback.format_exc())

Query a playback credential

You can call the GetVideoPlayAuth operation to query a playback credential.

For more information about the request and response parameters of this operation, see GetVideoPlayAuth. Example:

from aliyunsdkvod.request.v20170321 import GetVideoPlayAuthRequest
def get_video_playauth(clt, videoId):
    request = GetVideoPlayAuthRequest.GetVideoPlayAuthRequest()
    request.set_accept_format('JSON')
    request.set_VideoId(videoId)
    request.set_AuthInfoTimeout(3000)
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    playAuth = get_video_playauth(clt, '<videoId>')
    print(json.dumps(playAuth, ensure_ascii=False, indent=4))

except Exception as e:
    print(e)
    print(traceback.format_exc())