全部产品
云市场

音视频播放

更新时间:2018-12-30 17:20:35

初始化客户端

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

获取视频播放地址

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

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Profile;
  4. using Aliyun.Acs.Core.Exceptions;
  5. using Aliyun.Acs.vod.Model.V20170321;
  6. using System.Collections.Generic;
  7. namespace Aliyun.Acs.vod.Sdk.Sample
  8. {
  9. class MainClass
  10. {
  11. public static void Main(string[] args)
  12. {
  13. try
  14. {
  15. // 构造请求
  16. GetPlayInfoRequest request = new GetPlayInfoRequest();
  17. request.VideoId = "<your VideoId>";
  18. // request.AuthTimeout = 3600;
  19. // 初始化客户端
  20. DefaultAcsClient client = InitVodClient();
  21. // 发起请求,并得到 response
  22. GetPlayInfoResponse response = client.GetAcsResponse(request);
  23. Console.WriteLine("RequestId = " + response.RequestId);
  24. Console.WriteLine("VideoBase.Title = " + response.VideoBase.Title);
  25. List<GetPlayInfoResponse.GetPlayInfo_PlayInfo> playInfoList = response.PlayInfoList;
  26. foreach (var playInfo in response.PlayInfoList)
  27. {
  28. Console.WriteLine("PlayInfoList.PlayURL = " + playInfo.PlayURL);
  29. }
  30. }
  31. catch (ServerException ex)
  32. {
  33. Console.WriteLine(ex.ToString());
  34. }
  35. catch (ClientException ex)
  36. {
  37. Console.WriteLine(ex.ToString());
  38. }
  39. }
  40. }
  41. }

获取视频播放凭证

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

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Profile;
  4. using Aliyun.Acs.Core.Exceptions;
  5. using Aliyun.Acs.vod.Model.V20170321;
  6. namespace Aliyun.Acs.vod.Sdk.Sample
  7. {
  8. class MainClass
  9. {
  10. public static void Main(string[] args)
  11. {
  12. try
  13. {
  14. // 构造请求
  15. GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
  16. request.VideoId = "<your VideoId>";
  17. //request.AuthInfoTimeout = 3000;
  18. // 初始化客户端
  19. DefaultAcsClient client = InitVodClient();
  20. // 发起请求,并得到 response
  21. GetVideoPlayAuthResponse response = client.GetAcsResponse(request);
  22. Console.WriteLine("RequestId = " + response.RequestId);
  23. Console.WriteLine("VideoMeta.Title = " + response.VideoMeta.Title);
  24. Console.WriteLine("PlayAuth = " + response.PlayAuth);
  25. }
  26. catch (ServerException ex)
  27. {
  28. Console.WriteLine(ex.ToString());
  29. }
  30. catch (ClientException ex)
  31. {
  32. Console.WriteLine(ex.ToString());
  33. }
  34. }
  35. }
  36. }