官方SDK文档地址: https://help.aliyun.com/document_detail/57756.html?spm=a2c4g.11186623.6.904.4e0d3bd9VbkICO

1、引入maven依赖

<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.3.3</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-vod</artifactId>
<version>2.15.5</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
</dependency>

 

2、application.yml配置

#阿里云accessKeyId
video_accessKeyId: LTAI
#阿里云accessKeySecret
video_accessKeySecret: kKUciySv0
#阿里云账号ID 值的来源https://help.aliyun.com/knowledge_detail/37196.html
video_userId: 10

  

 

3、控制器类

AliyunVideoController.java

(RequestUtils为获取参数的工具类,可以不使用这种方式)

RequestUtils地址:https://www.cnblogs.com/pxblog/p/12238509.html

package cn.controller;

import cn.RequestUtils;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.vod.model.v20170321.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List; @Controller
public class AliyunVideoController { @Value("${video_accessKeyId}")
private String accessKeyId; @Value("${video_accessKeySecret}")
private String accessKeySecret; @Value("${video_userId}")
private String videoUserId; /**
* 获取视频上传地址和凭证
*
*/
@RequestMapping("/aliyunVideo/createUploadVideo")
@ResponseBody
public void createUploadVideo(HttpServletRequest request, HttpServletResponse httpServletResponse) {
DefaultAcsClient client = initVodClient();
CreateUploadVideoResponse response = new CreateUploadVideoResponse();
String title= RequestUtils.getQueryParam(request,"title"); //视频标题
String fileName= RequestUtils.getQueryParam(request,"fileName"); //文件名称
try {
response = createUploadVideo(client,title,fileName);
System.out.print("VideoId = " + response.getVideoId() + "\n");
System.out.print("UploadAddress = " + response.getUploadAddress() + "\n");
System.out.print("UploadAuth = " + response.getUploadAuth() + "\n");
} catch (Exception e) {
System.out.print("ErrorMessage = " + e.getLocalizedMessage());
}
System.out.print("RequestId = " + response.getRequestId() + "\n");
} /**
* 获取视频上传地址和凭证
*
* @param client 发送请求客户端
* @return CreateUploadVideoResponse 获取视频上传地址和凭证响应数据
* @throws Exception
*/
public static CreateUploadVideoResponse createUploadVideo(DefaultAcsClient client,String title,String fileName) {
try {
CreateUploadVideoRequest request = new CreateUploadVideoRequest();
request.setTitle(title);
request.setFileName(fileName);
return client.getAcsResponse(request);
} catch (ClientException e) {
e.printStackTrace();
}
return null;
} /**
* 刷新视频上传凭证
*
*/
@RequestMapping(value = "/aliyunVideo/refreshUploadVideo")
@ResponseBody
public void refreshUploadVideo(HttpServletRequest request){
String videoId=RequestUtils.getQueryParam(request,"videoId");
DefaultAcsClient client = initVodClient();
RefreshUploadVideoResponse response = new RefreshUploadVideoResponse();
try {
response = refreshUploadVideo(client,videoId);
System.out.print("UploadAddress = " + response.getUploadAddress() + "\n");
System.out.print("UploadAuth = " + response.getUploadAuth() + "\n");
} catch (Exception e) {
System.out.print("ErrorMessage = " + e.getLocalizedMessage());
}
System.out.print("RequestId = " + response.getRequestId() + "\n");
} /**
* 刷新视频上传凭证
*
* @param client 发送请求客户端
* @return RefreshUploadVideoResponse 刷新视频上传凭证响应数据
* @throws Exception
*/
public static RefreshUploadVideoResponse refreshUploadVideo(DefaultAcsClient client,String videoId) throws Exception {
RefreshUploadVideoRequest request = new RefreshUploadVideoRequest();
request.setVideoId(videoId);
return client.getAcsResponse(request);
} /**
* 获取播放地址函数
* 直接获取播放地址,可以使用任意播放器直接播放
* @param request
*/
@RequestMapping(value = "/aliyunVideo/getPlayInfo")
@ResponseBody
public void getPlayInfo(HttpServletRequest request){
String videoId=RequestUtils.getQueryParam(request,"videoId");
DefaultAcsClient client = initVodClient();
GetPlayInfoResponse response = new GetPlayInfoResponse();
try {
response = getPlayInfo(client,videoId);
List<GetPlayInfoResponse.PlayInfo> playInfoList = response.getPlayInfoList();
//播放地址
for (GetPlayInfoResponse.PlayInfo playInfo : playInfoList) {
System.out.print("PlayInfo.PlayURL = " + playInfo.getPlayURL() + "\n");
}
//Base信息
System.out.print("VideoBase.Title = " + response.getVideoBase().getTitle() + "\n");
} catch (Exception e) {
System.out.print("ErrorMessage = " + e.getLocalizedMessage());
}
System.out.print("RequestId = " + response.getRequestId() + "\n");
} /*获取播放地址函数*/
public static GetPlayInfoResponse getPlayInfo(DefaultAcsClient client,String videoId) throws Exception {
GetPlayInfoRequest request = new GetPlayInfoRequest();
request.setVideoId(videoId);
return client.getAcsResponse(request);
} /**
* 获取播放凭证函数
* 必须使用阿里云播放器进行播放
* @param request
*/
@RequestMapping(value = "/aliyunVideo/getVideoPlayAuth")
public void getVideoPlayAuth(HttpServletRequest request){
String videoId=RequestUtils.getQueryParam(request,"videoId");
DefaultAcsClient client = initVodClient();
GetVideoPlayAuthResponse response = new GetVideoPlayAuthResponse();
try {
response = getVideoPlayAuth(client,videoId);
//播放凭证
System.out.print("PlayAuth = " + response.getPlayAuth() + "\n");
//VideoMeta信息
System.out.print("VideoMeta.Title = " + response.getVideoMeta().getTitle() + "\n");
} catch (Exception e) {
System.out.print("ErrorMessage = " + e.getLocalizedMessage());
}
System.out.print("RequestId = " + response.getRequestId() + "\n"); } /*获取播放凭证函数*/
public static GetVideoPlayAuthResponse getVideoPlayAuth(DefaultAcsClient client,String videoId) throws Exception {
GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
request.setVideoId(videoId);
return client.getAcsResponse(request);
} @PostConstruct
public DefaultAcsClient initVodClient() {
try {
String regionId = "cn-shanghai"; // 点播服务接入区域
DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
DefaultAcsClient client = new DefaultAcsClient(profile);
return client;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

  

springboot整合阿里云视频点播接口的更多相关文章

  1. SpringBoot整合阿里云OSS文件上传、下载、查看、删除

    1. 开发前准备 1.1 前置知识 java基础以及SpringBoot简单基础知识即可. 1.2 环境参数 开发工具:IDEA 基础环境:Maven+JDK8 所用技术:SpringBoot.lom ...

  2. SpringBoot整合阿里云OSS对象存储实现文件上传

    1. 准备工作: 一.首先登录阿里云OSS对象存储控制台创建一个Bucket作为你的存储空间. 二.创建Access Keyan按要求创建进行,这里的方法步骤我就不展现出来了,你们可以自行查询阿里云文 ...

  3. SpringBoot整合阿里短信服务

    导读 由于最近手头上需要做个Message Gateway,涉及到:邮件(点我直达).短信.公众号(点我直达)等推送功能,网上学习下,整理下来以备以后使用. 步骤 点我直达 登录短信服务控制台 点我直 ...

  4. 阿里云视频点播之URL批量拉取上传(调整为多个视频上传)

    项目引入阿里云视频点播PHP-SDK 背景:2021年乐视云的点播将停止提供服务,项目决定选择选用阿里云的视频的点播.在上线前,需要将之前的视频提前导入资源库,URLS方式拉取是比较方便的,对编辑同事 ...

  5. 整合阿里云OSS

    整合阿里云OSS 一.对象存储OSS 为了解决海量数据存储与弹性扩容,采用云存储的解决方案- 阿里云OSS. 1.开通"对象存储OSS"服务 (1)申请阿里云账号 (2)实名认证 ...

  6. 在OneThink(ThinkPHP3.2.3)中整合阿里云OSS的PHP-SDK2.0.4,实现Web端直传,服务端签名直传并设置上传回调的实现流程

    在OneThink(ThinkPHP3.2.3)中整合阿里云OSS的PHP-SDK2.0.4,实现本地文件上传流程 by shuijingwan · 2016/01/13 1.SDK安装 github ...

  7. Thinkphp整合阿里云OSS图片上传实例

    Thinkphp3.2整合阿里云OSS图片上传实例,图片上传至OSS可减少服务器压力,节省宽带,安全又稳定,阿里云OSS对于做负载均衡非常方便,不用传到各个服务器了 首先引入阿里云OSS类库 < ...

  8. SpringBoot整合阿里Druid数据源及Spring-Data-Jpa

    SpringBoot整合阿里Druid数据源及Spring-Data-Jpa https://mp.weixin.qq.com/s?__biz=MzU0MDEwMjgwNA==&mid=224 ...

  9. 通过AccessKey调用阿里云CDN接口刷新CDN资源案例

    通过AccessKey远程调用阿里云CDN接口,快速实现自动化集成部署. CdnService.java package com.nfky.cdn; import com.aliyuncs.Defau ...

随机推荐

  1. admixture 群体结构分析

    tructure是与PCA.进化树相似的方法,就是利用分子标记的基因型信息对一组样本进行分类,分子标记可以是SNP.indel.SSR.相比于PCA,进化树,群体结构分析可明确各个群之间是否存在交流及 ...

  2. 2021-2-3-利用anaconda+prefetch+aspera从NCBI的SRA数据库中下载原始测序数据

    目录 1.Conda连接不上镜像源问题 2. aspera不能再独立使用 3.使用prefetch搭配aspera 4. prefetch下载方法 记录下下载过程,为自己和后人避坑. 1.Conda连 ...

  3. Linux系统中安装软件方法总结

    Linux系统中安装软件方法总结 [1]Linux系统中安装软件的几种方式 [2] Linux配置yum源(本地源和网络源) [3] SuSE下zypper源配置 [4] SUSE zypper 本地 ...

  4. Stream.toMap

    Collectors类的tomap方法将流收集到映射实例中. list 转 map collection.stream().collect(Collectors.toMap(User::getId, ...

  5. SSH服务及通过SSH方式登录linux

    SSH服务及通过SSH方式登录linux 1.检查SSH服务转自:[1]Linux之sshd服务https://www.cnblogs.com/uthnb/p/9367875.html[2]Linux ...

  6. Linux学习 - 系统命令sudo权限

    1 功能 root把超级用执行的命令赋予普通用户执行 2 使用 visudo 或 vim /etc/sudoers 说明: root 用户名 ALL=(ALL) 被管理主机的地址=(可使用的身份) A ...

  7. vue 第三方图标库

    "font-awesome": "^4.7.0", "dependencies": { "axios": "^ ...

  8. Shell脚本实现自动修改IP地址

    作为一名Linux SA,日常运维中很多地方都会用到脚本,而服务器的ip一般采用静态ip或者MAC绑定,当然后者比较操作起来相对繁琐,而前者我们可以设置主机名.ip信息.网关等配置.修改成特定的主机名 ...

  9. 【Java多线程】ExecutorService和ThreadPoolExecutor

    ExecutorService Java.util.concurrent.ExecutorService接口代表一种异步执行机制,它能够在后台执行任务.因此ExecutorService与thread ...

  10. Java 设计模式--策略模式,枚举+工厂方法实现

    如果项目中的一个页面跳转功能存在10个以上的if else判断,想要做一下整改 一.什么是策略模式 策略模式是对算法的包装,是把使用算法的责任和算法本身分割开来,委派给不同的对象管理,最终可以实现解决 ...