全部产品
云市场

截图模板

更新时间:2018-12-29 11:43:47

初始化客户端

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

添加截图模板

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

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Exceptions;
  4. using Aliyun.Acs.Core.Profile;
  5. using Aliyun.Acs.vod.Model.V20170321;
  6. using Newtonsoft.Json.Linq;
  7. namespace Aliyun.Acs.vod.Sdk.AddVodTemplate
  8. {
  9. class MainClass
  10. {
  11. /// <summary>
  12. /// 主函数
  13. /// </summary>
  14. /// <param name="args">The command-line arguments.</param>
  15. public static void Main(string[] args)
  16. {
  17. try
  18. {
  19. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  20. // 发起请求,并得到 response
  21. AddVodTemplateResponse response = AddVodTemplate(client);
  22. Console.WriteLine("RequestId = " + response.RequestId);
  23. }
  24. catch (ServerException e)
  25. {
  26. if (e.RequestId != null)
  27. {
  28. Console.WriteLine("RequestId = " + e.RequestId);
  29. }
  30. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  31. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  32. }
  33. catch (ClientException e)
  34. {
  35. if (e.RequestId != null)
  36. {
  37. Console.WriteLine("RequestId = " + e.RequestId);
  38. }
  39. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  40. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  41. }
  42. catch (Exception e)
  43. {
  44. Console.WriteLine("ErrorMessage = " + e.ToString());
  45. }
  46. }
  47. /// <summary>
  48. /// 添加截图模板函数
  49. /// </summary>
  50. /// <returns>The vod template.</returns>
  51. /// <param name="client">Client.</param>
  52. public static AddVodTemplateResponse AddVodTemplate(DefaultAcsClient client)
  53. {
  54. // 构造请求
  55. AddVodTemplateRequest request = new AddVodTemplateRequest();
  56. // 模板名称
  57. request.Name = "addVodTemplate";
  58. // 模板类型,固定值为Snapshot
  59. request.TemplateType = "Snapshot";
  60. // 截图模板配置数据生成
  61. request.TemplateConfig = BuildSnapshotTemplateConfig();
  62. return client.GetAcsResponse(request);
  63. }
  64. /// <summary>
  65. /// 构建截图模板的配置数据,根据具体设置需求修改对应的参数值
  66. /// (以下代码示例为雪碧图完整配置)
  67. /// </summary>
  68. /// <returns>截图模板的配置</returns>
  69. public static string BuildSnapshotTemplateConfig()
  70. {
  71. JObject templateConfig = new JObject();
  72. JObject snapshotConfig = new JObject();
  73. snapshotConfig.Add("Count", "50");
  74. snapshotConfig.Add("Interval", "1");
  75. snapshotConfig.Add("SpecifiedOffsetTime", "0");
  76. snapshotConfig.Add("Width", "200");
  77. snapshotConfig.Add("Height", "200");
  78. // 普通截图配置(与雪碧图原始图配置共用该配置信息)
  79. templateConfig.Add("SnapshotConfig", snapshotConfig);
  80. //雪碧图配置(雪碧图配置必须是建立在普通截图配置之上)
  81. JObject spriteSnapshotConfig = new JObject();
  82. spriteSnapshotConfig.Add("CellWidth", "120");
  83. spriteSnapshotConfig.Add("CellHeight", "68");
  84. spriteSnapshotConfig.Add("Columns", "3");
  85. spriteSnapshotConfig.Add("Lines", "10");
  86. spriteSnapshotConfig.Add("Padding", "20");
  87. spriteSnapshotConfig.Add("Margin", "50");
  88. spriteSnapshotConfig.Add("KeepCellPic", "keep");
  89. spriteSnapshotConfig.Add("Color", "tomato");
  90. snapshotConfig.Add("SpriteSnapshotConfig", spriteSnapshotConfig);
  91. //截图类型(存在雪碧图配置,该类型必须是"SpriteSnapshot",否则为"NormalSnapshot")
  92. templateConfig.Add("SnapshotType", "SpriteSnapshot");
  93. return templateConfig.ToString();
  94. }
  95. }
  96. }

修改截图模板

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

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Exceptions;
  4. using Aliyun.Acs.Core.Profile;
  5. using Aliyun.Acs.vod.Model.V20170321;
  6. using Newtonsoft.Json.Linq;
  7. namespace Aliyun.Acs.vod.Sdk.UpdateVodTemplate
  8. {
  9. class MainClass
  10. {
  11. /// <summary>
  12. /// 主函数
  13. /// </summary>
  14. /// <param name="args">The command-line arguments.</param>
  15. public static void Main(string[] args)
  16. {
  17. try
  18. {
  19. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  20. // 发起请求,并得到 response
  21. UpdateVodTemplateResponse response = UpdateVodTemplate(client);
  22. Console.WriteLine("RequestId = " + response.RequestId);
  23. }
  24. catch (ServerException e)
  25. {
  26. if (e.RequestId != null)
  27. {
  28. Console.WriteLine("RequestId = " + e.RequestId);
  29. }
  30. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  31. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  32. }
  33. catch (ClientException e)
  34. {
  35. if (e.RequestId != null)
  36. {
  37. Console.WriteLine("RequestId = " + e.RequestId);
  38. }
  39. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  40. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  41. }
  42. catch (Exception e)
  43. {
  44. Console.WriteLine("ErrorMessage = " + e.ToString());
  45. }
  46. }
  47. /// <summary>
  48. /// 修改截图模板函数
  49. /// </summary>
  50. /// <returns>UpdateVodTemplateResponse</returns>
  51. /// <param name="client">Client.</param>
  52. public static UpdateVodTemplateResponse UpdateVodTemplate(DefaultAcsClient client)
  53. {
  54. // 构造请求
  55. UpdateVodTemplateRequest request = new UpdateVodTemplateRequest();
  56. request.VodTemplateId = "53azf9d796fad9d7b862b2e5e5b";
  57. // 模板名称
  58. request.Name = "new template name";
  59. // 截图模板配置数据生成
  60. request.TemplateConfig = BuildSnapshotTemplateConfig();
  61. return client.GetAcsResponse(request);
  62. }
  63. /// <summary>
  64. /// 构建截图模板的配置数据,根据具体设置需求修改对应的参数值
  65. /// (以下代码示例为普通截图完整配置)
  66. /// </summary>
  67. /// <returns>截图模板的配置</returns>
  68. public static string BuildSnapshotTemplateConfig()
  69. {
  70. JObject templateConfig = new JObject();
  71. JObject snapshotConfig = new JObject();
  72. snapshotConfig.Add("Count", "50");
  73. snapshotConfig.Add("Interval", "1");
  74. snapshotConfig.Add("SpecifiedOffsetTime", "0");
  75. snapshotConfig.Add("Width", "200");
  76. snapshotConfig.Add("Height", "200");
  77. // 普通截图配置(与雪碧图原始图配置共用该配置信息)
  78. templateConfig.Add("SnapshotConfig", snapshotConfig);
  79. //截图类型(存在雪碧图配置,该类型必须是"SpriteSnapshot",否则为"NormalSnapshot")
  80. templateConfig.Add("SnapshotType", "SpriteSnapshot");
  81. return templateConfig.ToString();
  82. }
  83. }
  84. }

删除截图模板

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

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Exceptions;
  4. using Aliyun.Acs.Core.Profile;
  5. using Aliyun.Acs.vod.Model.V20170321;
  6. namespace Aliyun.Acs.vod.Sdk.DeleteVodTemplate
  7. {
  8. class MainClass
  9. {
  10. /// <summary>
  11. /// 主函数
  12. /// </summary>
  13. /// <param name="args">The command-line arguments.</param>
  14. public static void Main(string[] args)
  15. {
  16. try
  17. {
  18. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  19. // 发起请求,并得到 response
  20. DeleteVodTemplateResponse response = DeleteVodTemplate(client);
  21. Console.WriteLine("RequestId = " + response.RequestId);
  22. }
  23. catch (ServerException e)
  24. {
  25. if (e.RequestId != null)
  26. {
  27. Console.WriteLine("RequestId = " + e.RequestId);
  28. }
  29. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  30. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  31. }
  32. catch (ClientException e)
  33. {
  34. if (e.RequestId != null)
  35. {
  36. Console.WriteLine("RequestId = " + e.RequestId);
  37. }
  38. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  39. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  40. }
  41. catch (Exception e)
  42. {
  43. Console.WriteLine("ErrorMessage = " + e.ToString());
  44. }
  45. }
  46. /// <summary>
  47. /// Deletes the vod template.
  48. /// </summary>
  49. /// <returns>The vod template.</returns>
  50. /// <param name="client">Client.</param>
  51. public static DeleteVodTemplateResponse DeleteVodTemplate(DefaultAcsClient client)
  52. {
  53. // 构造请求
  54. DeleteVodTemplateRequest request = new DeleteVodTemplateRequest();
  55. //设置要删除的模板ID
  56. request.VodTemplateId = "53azf9d796fad9d7b862b2e5e5b";
  57. return client.GetAcsResponse(request);
  58. }
  59. }
  60. }

查询截图模板列表

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

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Exceptions;
  4. using Aliyun.Acs.Core.Profile;
  5. using Aliyun.Acs.vod.Model.V20170321;
  6. namespace Aliyun.Acs.vod.Sdk.ListVodTemplate
  7. {
  8. class MainClass
  9. {
  10. /// <summary>
  11. /// 主函数
  12. /// </summary>
  13. /// <param name="args">The command-line arguments.</param>
  14. public static void Main(string[] args)
  15. {
  16. try
  17. {
  18. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  19. // 发起请求,并得到 response
  20. ListVodTemplateResponse response = ListVodTemplate(client);
  21. if (response.VodTemplateInfoList != null && response.VodTemplateInfoList.Count > 0)
  22. {
  23. foreach (ListVodTemplateResponse.ListVodTemplate_VodTemplateInfo templateInfo in response.VodTemplateInfoList)
  24. {
  25. // 模板ID
  26. Console.WriteLine("VodTemplateId = " + templateInfo.VodTemplateId);
  27. // 模板名称
  28. Console.WriteLine("Name = " + templateInfo.Name);
  29. }
  30. }
  31. Console.WriteLine("RequestId = " + response.RequestId);
  32. }
  33. catch (ServerException e)
  34. {
  35. if (e.RequestId != null)
  36. {
  37. Console.WriteLine("RequestId = " + e.RequestId);
  38. }
  39. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  40. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  41. }
  42. catch (ClientException e)
  43. {
  44. if (e.RequestId != null)
  45. {
  46. Console.WriteLine("RequestId = " + e.RequestId);
  47. }
  48. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  49. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  50. }
  51. catch (Exception e)
  52. {
  53. Console.WriteLine("ErrorMessage = " + e.ToString());
  54. }
  55. }
  56. /// <summary>
  57. /// Lists the vod template.
  58. /// </summary>
  59. /// <returns>The vod template.</returns>
  60. /// <param name="client">Client.</param>
  61. public static ListVodTemplateResponse ListVodTemplate(DefaultAcsClient client)
  62. {
  63. // 构造请求
  64. ListVodTemplateRequest request = new ListVodTemplateRequest();
  65. //模板类型,固定值为Snapshot
  66. request.TemplateType = "Snapshot";
  67. return client.GetAcsResponse(request);
  68. }
  69. }
  70. }

查询截图模板

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

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Exceptions;
  4. using Aliyun.Acs.Core.Profile;
  5. using Aliyun.Acs.vod.Model.V20170321;
  6. namespace Aliyun.Acs.vod.Sdk.GetVodTemplate
  7. {
  8. class MainClass
  9. {
  10. /// <summary>
  11. /// 主函数
  12. /// </summary>
  13. /// <param name="args">The command-line arguments.</param>
  14. public static void Main(string[] args)
  15. {
  16. try
  17. {
  18. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  19. // 发起请求,并得到 response
  20. GetVodTemplateResponse response = GetVodTemplate(client);
  21. if (response.VodTemplateInfo != null)
  22. {
  23. // 模板ID
  24. Console.WriteLine("VodTemplateId = " + templateInfo.VodTemplateId);
  25. // 模板名称
  26. Console.WriteLine("Name = " + templateInfo.Name);
  27. }
  28. Console.WriteLine("RequestId = " + response.RequestId);
  29. }
  30. catch (ServerException e)
  31. {
  32. if (e.RequestId != null)
  33. {
  34. Console.WriteLine("RequestId = " + e.RequestId);
  35. }
  36. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  37. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  38. }
  39. catch (ClientException e)
  40. {
  41. if (e.RequestId != null)
  42. {
  43. Console.WriteLine("RequestId = " + e.RequestId);
  44. }
  45. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  46. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  47. }
  48. catch (Exception e)
  49. {
  50. Console.WriteLine("ErrorMessage = " + e.ToString());
  51. }
  52. }
  53. /// <summary>
  54. /// Gets the vod template.
  55. /// </summary>
  56. /// <returns>The vod template.</returns>
  57. /// <param name="client">Client.</param>
  58. public static GetVodTemplateResponse GetVodTemplate(DefaultAcsClient client)
  59. {
  60. // 构造请求
  61. GetVodTemplateRequest request = new GetVodTemplateRequest();
  62. // 设置要查询的模板ID
  63. request.VodTemplateId = "53azf9d796fad9d7b862b2e5e5b";
  64. return client.GetAcsResponse(request);
  65. }
  66. }
  67. }