一、准备工作

1、设置不转码

测试之前设置默认“不转码”,以节省开发成本

2、找到子账户的AccessKey ID

3、给子账户添加授权

AliyunVODFullAccess

4、阅读文档

服务端API:

API调用示例参考:https://help.aliyun.com/document_detail/44435.html?spm=a2c4g.11186623.6.708.2c643d44SY21Hb

服务端SDK:

SDK将API进行了进一步的封装,使用起来更简单方便

二、创建和初始化项目

1、创建maven项目

Group:com.atguigu

Artifact:aliyun_vod

2、添加Maven依赖

<dependencies>
<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.2</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>

3、创建测试类并初始化

参考文档:https://help.aliyun.com/document_detail/61062.html

package com.atguigu.aliyunvod;

public class VodSdkTest {
public static DefaultAcsClient initVodClient(String accessKeyId, String accessKeySecret) {
String regionId = "cn-shanghai"; // 点播服务接入区域
DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
DefaultAcsClient client = new DefaultAcsClient(profile);
return client;
}
}

三、创建测试用例

1、获取视频播放地址

参考文档:https://help.aliyun.com/document_detail/61064.html

/*获取播放地址函数*/
public static GetPlayInfoResponse getPlayInfo(DefaultAcsClient client) throws Exception {
GetPlayInfoRequest request = new GetPlayInfoRequest();
request.setVideoId("视频ID");
//request.setResultType("Multiple"); //如果视频id是加密视频的id,则需要设置此参数。但只能获取文件无法解密播放
return client.getAcsResponse(request);
}
@Test
public void testGetPlayInfo(){
DefaultAcsClient client = initVodClient("<您的AccessKeyId>", "<您的AccessKeySecret>");
GetPlayInfoResponse response = new GetPlayInfoResponse(); try {
response = getPlayInfo(client);
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");
}

2、获取视频播放凭证

参考文档:https://help.aliyun.com/document_detail/61064.html#h2--div-id-getvideoplayauth-div-2

加密视频必须使用此方式播放

/*获取播放凭证函数*/
public static GetVideoPlayAuthResponse getVideoPlayAuth(DefaultAcsClient client) throws Exception {
GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
request.setVideoId("视频ID");
return client.getAcsResponse(request);
}
/*以下为调用示例*/
@Test
public void testGetVideoPlayAuth() { DefaultAcsClient client = initVodClient("<您的AccessKeyId>", "<您的AccessKeySecret>");
GetVideoPlayAuthResponse response = new GetVideoPlayAuthResponse();
try {
response = getVideoPlayAuth(client);
//播放凭证
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");
}

最新文章

  1. Oracle冷备迁移脚本(文件系统)
  2. Zabbix协议分析
  3. 逆序数2 HDOJ 1394 Minimum Inversion Number
  4. Apache Spark源码走读之4 -- DStream实时流数据处理
  5. hdu 1536 S-Nim
  6. XML工具类 - XmlUtils.java
  7. Linux下UDP收/发广播消息简单实现
  8. poj1742 Coins(多重背包+单调队列优化)
  9. java数组并集/交集/差集(补集)
  10. IOS 快速排序法
  11. HDU 2040 亲和数
  12. 2017 ZSTU寒假排位赛 #1
  13. RESTful杂记
  14. Android系统修改之Notification布局修改(一)
  15. Python 多线程的程序不结束多进程的程序不结束的区别
  16. C# 对结构体和指针的使用
  17. Beta冲刺! Day1 - 磨刀
  18. 【洛谷P2746】Network of Schools
  19. Flask web开发之路九
  20. MINIUI后台获取数据

热门文章

  1. WIN7环境下配置vscode c++环境
  2. pytorch实现 | Deformable Convolutional Networks | CVPR | 2017
  3. 用Wireshark对Android应用的网络流量进行抓包
  4. 将XML转换为实体
  5. WPF 中的相关样式
  6. jmeter+jdk环境配置
  7. [LeetCode]2. Add Two Numbers链表相加
  8. 什么是ResultSet
  9. MongoDb学习三(spring-data-mongodb)
  10. [简单-剑指 Offer 53 - I. 在排序数组中查找数字 I]