全部产品
云市场

音视频播放

更新时间:2018-12-28 21:12:50

初始化客户端

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

获取视频播放地址

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

  1. // 调用样例
  2. var client = initVodClient('<Your AccessKeyId>','<Your AccessKeySecret>');
  3. client.request("GetPlayInfo", {
  4. VideoId: 'VideoId'
  5. }, {}).then(function (response) {
  6. // play url
  7. if (response.PlayInfoList && response.PlayInfoList.PlayInfo && response.PlayInfoList.PlayInfo.length > 0){
  8. for (var i=0; i<response.PlayInfoList.PlayInfo.length; i++){
  9. console.log("PlayInfo.PlayURL = " + response.PlayInfoList.PlayInfo[i].PlayURL);
  10. }
  11. }
  12. // base metadata
  13. if (response.VideoBase){
  14. console.log('VideoBase.Title = ' + response.VideoBase.Title);
  15. }
  16. console.log('RequestId = ' + response.RequestId);
  17. }).catch(function (response) {
  18. console.log('ErrorCode = ' + response.data.Code);
  19. console.log('ErrorMessage = ' + response.data.Message);
  20. console.log('RequestId = ' + response.data.RequestId);
  21. });

获取视频播放凭证

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

  1. // 调用样例
  2. var client = initVodClient('<Your AccessKeyId>','<Your AccessKeySecret>');
  3. client.request("GetVideoPlayAuth", {
  4. VideoId: 'VideoId'
  5. }, {}).then(function (response) {
  6. // play auth
  7. console.log('PlayAuth = ' + response.PlayAuth);
  8. // base metadata
  9. if (response.VideoMeta){
  10. console.log('VideoMeta.Title = ' + response.VideoMeta.Title);
  11. }
  12. console.log('RequestId = ' + response.RequestId);
  13. }).catch(function (response) {
  14. console.log('ErrorCode = ' + response.data.Code);
  15. console.log('ErrorMessage = ' + response.data.Message);
  16. console.log('RequestId = ' + response.data.RequestId);
  17. });