全部产品

音视频播放

本篇文档提供了Python SDK音视频播放模块相关功能的API调用示例。包含获取播放地址、获取视频播放凭证。

初始化客户端

使用前请先初始化客户端,请参见初始化

获取播放地址

调用GetPlayInfo接口,完成获取播放地址功能。

接口参数和返回字段请参见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())

获取视频播放凭证

调用GetVideoPlayAuth接口,完成获取视频播放凭证功能。

接口参数和返回字段请参见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(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())