全部产品
云市场

音视频播放

更新时间:2019-06-17 11:54:40

初始化客户端

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

获取播放地址

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

  1. from aliyunsdkvod.request.v20170321 import GetPlayInfoRequest
  2. def get_play_info(clt, videoId):
  3. request = GetPlayInfoRequest.GetPlayInfoRequest()
  4. request.set_accept_format('JSON')
  5. request.set_VideoId(videoId)
  6. request.set_AuthTimeout(3600*5)
  7. response = json.loads(clt.do_action_with_exception(request))
  8. return response
  9. try:
  10. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  11. playInfo = get_play_info(clt, '<videoId>')
  12. print(json.dumps(playInfo, ensure_ascii=False, indent=4))
  13. except Exception as e:
  14. print(e)
  15. print(traceback.format_exc())

获取播放凭证

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

  1. from aliyunsdkvod.request.v20170321 import GetVideoPlayAuthRequest
  2. def get_video_playauth(clt, videoId):
  3. request = GetVideoPlayAuthRequest.GetVideoPlayAuthRequest()
  4. request.set_accept_format('JSON')
  5. request.set_VideoId(videoId)
  6. request.set_AuthInfoTimeout(3000)
  7. response = json.loads(clt.do_action_with_exception(request))
  8. return response
  9. try:
  10. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  11. playAuth = get_video_playauth(clt, '<videoId>')
  12. print(json.dumps(playAuth, ensure_ascii=False, indent=4))
  13. except Exception as e:
  14. print(e)
  15. print(traceback.format_exc())