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 init_vod_client.

Obtain the audio or video playback URL

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

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())

Obtain the video playback credential

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

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(3600)
    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())