当前位置:   article > 正文

阿里云视频点播(媒资上传)_yaml配置阿里云视频点播

yaml配置阿里云视频点播

在真实项目中,需要对阿里云点播操作进行代码集成。

1.写在配置文件中(application.yml)

  1. #阿里云配置
  2. aliyun:
  3. region: cn-shanghai #点播地域标识
  4. accessKeyId: #KeyId
  5. accessKeySecret: #KeySecret

2.配置对象

  1. @Data
  2. @ConfigurationProperties(prefix = "aliyun")
  3. @Configuration
  4. public class AliyunProperties {
  5. private String region;
  6. private String accessKeyId;
  7. private String accessKeySecret;
  8. @Bean
  9. public DefaultAcsClient client() {
  10. DefaultProfile profile = DefaultProfile.getProfile(
  11. region,
  12. accessKeyId,
  13. accessKeySecret);
  14. return new DefaultAcsClient(profile);
  15. }
  16. }

3.抽取工具对象

  1. /**
  2. * 视频上传工具类
  3. */
  4. @Component
  5. public class VodTemplate {
  6. @Autowired
  7. private DefaultAcsClient client;
  8. /**
  9. * 获取音/视频上传地址和凭证
  10. */
  11. public CreateUploadVideoResponse createUploadVideo(String title, String fileName) throws Exception {
  12. CreateUploadVideoRequest request = new CreateUploadVideoRequest();
  13. request.setTitle(title);
  14. request.setFileName(fileName);
  15. return client.getAcsResponse(request);
  16. }
  17. /**
  18. * 刷新音/视频上传凭证
  19. */
  20. public RefreshUploadVideoResponse refreshUploadVideo(String videoId) throws Exception {
  21. RefreshUploadVideoRequest request = new RefreshUploadVideoRequest();
  22. //音频或视频ID
  23. request.setVideoId(videoId);
  24. return client.getAcsResponse(request);
  25. }
  26. /*获取播放地址函数*/
  27. public GetPlayInfoResponse getPlayInfo(String videoId) throws Exception {
  28. GetPlayInfoRequest request = new GetPlayInfoRequest();
  29. request.setVideoId(videoId);
  30. return client.getAcsResponse(request);
  31. }
  32. /**
  33. * 删除视频
  34. */
  35. public DeleteVideoResponse deleteVideo(String videoId) throws Exception {
  36. DeleteVideoRequest request = new DeleteVideoRequest();
  37. //支持传入多个视频ID,多个用逗号分隔
  38. request.setVideoIds(videoId);
  39. return client.getAcsResponse(request);
  40. }
  41. }

 

解析播放地址URL时

  1. //获取videoId
  2. //调用获取播放地址函数
  3. GetPlayInfoResponse playInfo = template.getPlayInfo(videoId);
  4. //获取视频播放地址
  5. GetPlayInfoResponse.PlayInfo info = playInfo.getPlayInfoList().get(0);
  6. String playURL = info.getPlayURL();

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/246019
推荐阅读
相关标签
  

闽ICP备14008679号