全部产品
视频点播

Java版

更新时间:2017-07-14 14:34:04   分享:   

简介

以下文档描述的是视频播放流程中在服务端(Java)获取播放凭证的方法。

环境要求

Java 6+

Maven

安装

  • 添加maven仓库
  1. <repositories>
  2. <repository>
  3. <id>sonatype-nexus-staging</id>
  4. <name>Sonatype Nexus Staging</name>
  5. <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
  6. <releases>
  7. <enabled>true</enabled>
  8. </releases>
  9. <snapshots>
  10. <enabled>true</enabled>
  11. </snapshots>
  12. </repository>
  13. </repositories>
  • 添加Jar包依赖
  1. <dependency>
  2. <groupId>com.aliyun</groupId>
  3. <artifactId>aliyun-java-sdk-core</artifactId>
  4. <version>3.2.2</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>com.aliyun</groupId>
  8. <artifactId>aliyun-java-sdk-vod</artifactId>
  9. <version>2.2.0</version>
  10. </dependency>

接口说明

  • 引用
  1. import com.aliyuncs.DefaultAcsClient;
  2. import com.aliyuncs.profile.DefaultProfile;
  3. import com.aliyuncs.profile.IClientProfile;
  4. import com.aliyuncs.exceptions.ClientException;
  5. import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthRequest;
  6. import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;
  • 初始化
  1. import com.aliyuncs.profile.DefaultProfile;
  2. import com.aliyuncs.DefaultAcsClient;
  3. DefaultProfile profile = DefaultProfile.getProfile("cn-shanghai", accessKeyId, accessKeySecret);
  • 函数

获取播放凭证

  1. GetVideoPlayAuthResponse getVideoPlayAuth(DefaultAcsClient client) {
  2. GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
  3. request.setVideoId("视频ID");
  4. GetVideoPlayAuthResponse response = null;
  5. try {
  6. response = client.getAcsResponse(request);
  7. } catch (ServerException e) {
  8. throw new RuntimeException("GetVideoPlayAuthRequest Server failed");
  9. } catch (ClientException e) {
  10. throw new RuntimeException("GetVideoPlayAuthRequest Client failed");
  11. }
  12. response.getPlayAuth(); //播放凭证
  13. response.getVideoMeta(); //视频Meta信息
  14. return response;
  15. }
  • API调用示例
  1. DefaultAcsClient client = new DefaultAcsClient(profile);
  2. getVideoPlayAuth(client);
本文导读目录
本文导读目录
以上内容是否对您有帮助?