spring boot 快速入门 vod(视频点播)(使用vod之前建议先看我的oss上传服务)
生活随笔
收集整理的這篇文章主要介紹了
spring boot 快速入门 vod(视频点播)(使用vod之前建议先看我的oss上传服务)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.導入pom 注意最后的vod-upload 參考我的? ?將Vod集成到Maven
<dependency><groupId>com.aliyun</groupId><artifactId>aliyun-java-sdk-core</artifactId><version>4.5.1</version></dependency><dependency><groupId>com.aliyun.oss</groupId><artifactId>aliyun-sdk-oss</artifactId><version>3.10.2</version></dependency><dependency><groupId>com.aliyun</groupId><artifactId>aliyun-java-sdk-vod</artifactId><version>2.15.11</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.28</version></dependency><dependency><groupId>org.json</groupId><artifactId>json</artifactId><version>20170516</version></dependency><dependency><groupId>com.google.code.gson</groupId><artifactId>gson</artifactId><version>2.8.2</version></dependency><!--非開源 需要自己下載導入--><dependency><groupId>com.aliyun</groupId><artifactId>aliyun-sdk-vod-upload</artifactId><version>1.4.14</version></dependency>2.編寫配置類獲取重要參數? yml
yml文件:
aliyun:vod:keyid: LTAI5t917KtK4jMysr7q5dsasTRe #idkeysecret: TpCng6xABP3hqehI9NyMdsdaAVQBOXRkW #密鑰templateGroupId: 1 #轉碼模板workflowId: 2 #工作流對應配置類
import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component;@Data @Component @ConfigurationProperties(prefix = "aliyun.vod") public class VodProperties {private String keyid;private String keysecret;private String templateGroupId;private String workflowId; }3.編寫服務(服務包括上傳 刪除 批量刪除)
@Service @Slf4j public class VodVideoServiceImp implements VodVideoService {@Autowiredprivate VodProperties vodProperties;@Override//video上傳服務public String uploadVideo(InputStream inputStream, String originalFileName) {String title = originalFileName.substring(0, originalFileName.lastIndexOf("."));UploadStreamRequest request=new UploadStreamRequest(vodProperties.getKeyid(),vodProperties.getKeysecret(),title,originalFileName,inputStream);UploadVideoImpl uploadVideo=new UploadVideoImpl();UploadStreamResponse response=uploadVideo.uploadStream(request);String videoId=response.getVideoId();if (StringUtils.isEmpty(videoId)){log.info("阿里云上傳失敗"+response.getCode()+"-"+ response.getMessage());}return videoId;}//video刪除服務@Overridepublic void removeVideo(String id) throws ClientException {DefaultAcsClient client=invokeClient(vodProperties.getKeyid(),vodProperties.getKeysecret());DeleteVideoRequest request=new DeleteVideoRequest();request.setVideoIds(id);DeleteVideoResponse response=client.getAcsResponse(request);}//批量刪除video@Overridepublic void removeVideoByList(List<String> stringList) throws ClientException {DefaultAcsClient client=invokeClient(vodProperties.getKeyid(),vodProperties.getKeysecret());DeleteVideoRequest request=new DeleteVideoRequest();StringBuffer buffer=new StringBuffer();int size=stringList.size();for (int i = 0; i < size; i++) {buffer.append(stringList.get(i));//拼接if (i == size-1||i%20==19){ //一次性最大批處理20條request.setVideoIds(buffer.toString());client.getAcsResponse(request);}else if (i<19){buffer.append(",");}}}//初始化服務端public static DefaultAcsClient invokeClient(String accessKeyId,String accessKeySecret){String region="cn-shanghai";//接入地區DefaultProfile profile=DefaultProfile.getProfile(region,accessKeyId,accessKeySecret);DefaultAcsClient client=new DefaultAcsClient(profile);return client;} }總結
以上是生活随笔為你收集整理的spring boot 快速入门 vod(视频点播)(使用vod之前建议先看我的oss上传服务)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 计算机副教授要求,浙江大学计算机学院20
- 下一篇: opencv —— morphology