目录
1.控制台介绍
2.环境准备
3.视频上传
4.视频删除
5.获取播放地址
6.获取播放凭证
1.控制台介绍
存储小于50G免费的,转码、流量都是需要付费的
视频存储
需要配置域名
2.环境准备
需要拿到这个key和secret,配置在项目中
3.视频上传
/*** 上传视频*/public static void main(String[] arg) {String title = "测试标题视频-13-尚硅谷-谷粒学院-技术点-阿里云视频点播(上传视频)-upload sdk";String fileName = "/Users/lizhenghang/Desktop/gulivideo/13demo.mp4";UploadVideoRequest request = new UploadVideoRequest(AccessKeyId, AccessKeySecret, title, fileName);//可指定分片上传时每个分片的大小,默认为1M字节request.setPartSize(1 * 1024 * 1024L);//可指定分片上传时的并发线程数,默认为1(注:该配置会占用服务器CPU资源,需根据服务器情况指定)request.setTaskNum(1);// 是否开启断点续传,默认断点续传功能关闭。当网络不稳定或者程序崩溃时,再次发起相同上传请求,可以继续未完成的上传任务,适用于超时3000秒仍不能上传完成的大文件。// 注意: 断点续传开启后,会在上传过程中将上传位置写入本地磁盘文件,影响文件上传速度,请您根据实际情况选择是否开启*//*request.setEnableCheckpoint(false);// 设置自定义上传进度回调(必须继承 ProgressListener)// request.setProgressListener(new PutObjectProgressListener());UploadVideoImpl uploader = new UploadVideoImpl();UploadVideoResponse response = uploader.uploadVideo(request);System.out.print("RequestId=" + response.getRequestId()); //请求视频点播服务的请求IDboolean success = response.isSuccess();System.out.println(success);if (response.isSuccess()) {System.out.print("VideoId=" + response.getVideoId());} else {//* 如果设置回调URL无效,不影响视频上传,可以返回VideoId同时会返回错误码。其他情况上传失败时,VideoId为空,此时需要根据返回错误码分析具体错误原因 *//*System.out.print("VideoId=" + response.getVideoId());System.out.print("ErrorCode=" + response.getCode());System.out.print("ErrorMessage=" + response.getMessage());}}
4.视频删除
/*** 删除视频** @throws ClientException*/public static void delete() throws ClientException {DefaultAcsClient client = initVodClient(AccessKeyId, AccessKeySecret);DeleteVideoResponse response = new DeleteVideoResponse();DeleteVideoRequest request = new DeleteVideoRequest();//支持传入多个视频ID,多个用逗号分隔request.setVideoIds("4b5bc79ef2f74a8c84fcc2b77d28e5db");try {response = client.getAcsResponse(request);} catch (Exception e) {System.out.print("ErrorMessage = " + e.getLocalizedMessage());}System.out.print("RequestId = " + response.getRequestId() + "\n");}
5.获取播放地址
/*** 根据视频id获取视频播放地址** @throws ClientException*/public static void getPlayUrl() throws ClientException {// 创建初始化对象// 创建获取视频地址request和response// 向request对象里面设置视频id// 调用初始化对象里面的方法传递request,获取数据DefaultAcsClient client = initVodClient(AccessKeyId, AccessKeySecret);GetPlayInfoRequest request = new GetPlayInfoRequest();GetPlayInfoResponse response = new GetPlayInfoResponse();try {request.setVideoId("4ad82587528b4580b6dff10d60c93448");response = client.getAcsResponse(request);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");}
6.获取播放凭证
/*** 根据视频id获取视频播放凭证** @throws ClientException*/public static void getPlayAuto() throws ClientException {// 根据视频id获取视频播放凭证// 创建获取视频凭证request和responseDefaultAcsClient client = initVodClient(AccessKeyId, AccessKeySecret);GetVideoPlayAuthResponse response = new GetVideoPlayAuthResponse();try {GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();request.setVideoId("4ad82587528b4580b6dff10d60c93448");response = client.getAcsResponse(request);//播放凭证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");}
其他功能实现参照视频点播官方文档即可
https://help.aliyun.com/product/29932.html