赞
踩
在真实项目中,需要对阿里云点播操作进行代码集成。
1.写在配置文件中(application.yml)
- #阿里云配置
- aliyun:
- region: cn-shanghai #点播地域标识
- accessKeyId: #KeyId
- accessKeySecret: #KeySecret
2.配置对象
- @Data
- @ConfigurationProperties(prefix = "aliyun")
- @Configuration
- public class AliyunProperties {
-
- private String region;
- private String accessKeyId;
- private String accessKeySecret;
-
- @Bean
- public DefaultAcsClient client() {
- DefaultProfile profile = DefaultProfile.getProfile(
- region,
- accessKeyId,
- accessKeySecret);
- return new DefaultAcsClient(profile);
- }
- }
3.抽取工具对象
-
- /**
- * 视频上传工具类
- */
- @Component
- public class VodTemplate {
-
- @Autowired
- private DefaultAcsClient client;
-
- /**
- * 获取音/视频上传地址和凭证
- */
- public CreateUploadVideoResponse createUploadVideo(String title, String fileName) throws Exception {
- CreateUploadVideoRequest request = new CreateUploadVideoRequest();
- request.setTitle(title);
- request.setFileName(fileName);
-
- return client.getAcsResponse(request);
- }
-
- /**
- * 刷新音/视频上传凭证
- */
- public RefreshUploadVideoResponse refreshUploadVideo(String videoId) throws Exception {
- RefreshUploadVideoRequest request = new RefreshUploadVideoRequest();
- //音频或视频ID
- request.setVideoId(videoId);
- return client.getAcsResponse(request);
- }
-
- /*获取播放地址函数*/
- public GetPlayInfoResponse getPlayInfo(String videoId) throws Exception {
- GetPlayInfoRequest request = new GetPlayInfoRequest();
- request.setVideoId(videoId);
- return client.getAcsResponse(request);
- }
-
- /**
- * 删除视频
- */
- public DeleteVideoResponse deleteVideo(String videoId) throws Exception {
- DeleteVideoRequest request = new DeleteVideoRequest();
- //支持传入多个视频ID,多个用逗号分隔
- request.setVideoIds(videoId);
- return client.getAcsResponse(request);
- }
- }
解析播放地址URL时
- //获取videoId
- //调用获取播放地址函数
- GetPlayInfoResponse playInfo = template.getPlayInfo(videoId);
- //获取视频播放地址
- GetPlayInfoResponse.PlayInfo info = playInfo.getPlayInfoList().get(0);
- String playURL = info.getPlayURL();
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。