全部产品
云市场

音视频播放

更新时间:2018-12-25 15:29:26

初始化客户端

使用前请先初始化客户端,参考 initVodClient 接口。

获取视频播放地址

接口参数和返回字段请参考 GetPlayInfo

  1. import com.aliyuncs.vod.model.v20170321.GetPlayInfoRequest;
  2. import com.aliyuncs.vod.model.v20170321.GetPlayInfoResponse;
  3. /*获取播放地址函数*/
  4. public static GetPlayInfoResponse getPlayInfo(DefaultAcsClient client) throws Exception {
  5. GetPlayInfoRequest request = new GetPlayInfoRequest();
  6. request.setVideoId("视频ID");
  7. return client.getAcsResponse(request);
  8. }
  9. /*以下为调用示例*/
  10. public static void main(String[] argv) {
  11. DefaultAcsClient client = initVodClient("<您的AccessKeyId>", "<您的AccessKeySecret>");
  12. GetPlayInfoResponse response = new GetPlayInfoResponse();
  13. try {
  14. response = getPlayInfo(client);
  15. List<GetPlayInfoResponse.PlayInfo> playInfoList = response.getPlayInfoList();
  16. //播放地址
  17. for (GetPlayInfoResponse.PlayInfo playInfo : playInfoList) {
  18. System.out.print("PlayInfo.PlayURL = " + playInfo.getPlayURL() + "\n");
  19. }
  20. //Base信息
  21. System.out.print("VideoBase.Title = " + response.getVideoBase().getTitle() + "\n");
  22. } catch (Exception e) {
  23. System.out.print("ErrorMessage = " + e.getLocalizedMessage());
  24. }
  25. System.out.print("RequestId = " + response.getRequestId() + "\n");
  26. }

获取视频播放凭证

接口参数和返回字段请参考 GetVideoPlayAuth

  1. import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthRequest;
  2. import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;
  3. /*获取播放凭证函数*/
  4. public static GetVideoPlayAuthResponse getVideoPlayAuth(DefaultAcsClient client) throws Exception {
  5. GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
  6. request.setVideoId("视频ID");
  7. return client.getAcsResponse(request);
  8. }
  9. /*以下为调用示例*/
  10. public static void main(String[] argv) {
  11. DefaultAcsClient client = initVodClient("<您的AccessKeyId>", "<您的AccessKeySecret>");
  12. GetVideoPlayAuthResponse response = new GetVideoPlayAuthResponse();
  13. try {
  14. response = getVideoPlayAuth(client);
  15. //播放凭证
  16. System.out.print("PlayAuth = " + response.getPlayAuth() + "\n");
  17. //VideoMeta信息
  18. System.out.print("VideoMeta.Title = " + response.getVideoMeta().getTitle() + "\n");
  19. } catch (Exception e) {
  20. System.out.print("ErrorMessage = " + e.getLocalizedMessage());
  21. }
  22. System.out.print("RequestId = " + response.getRequestId() + "\n");
  23. }