上述通过java上传视频到阿里云我们每次上传的时候可以得到一个videoId,我们通过这个video得到视频的地址

这是我们上传的视频文件

 

 

我们看下视频地址

有三个视频,其中最后一个使我们加过水印之后的文件

 

 

下面我们来得到它的地址

//账号AK信息请填写(必选)
private static final String accessKeyId = "LTAI4Fx22************";
//账号AK信息请填写(必选)
private static final String accessKeySecret = "1jzu74S***************nd";
  @Test
public static void Address() {
DefaultAcsClient client = initVodClient(accessKeyId, accessKeySecret);
GetPlayInfoResponse response = new GetPlayInfoResponse();
try {
response = getPlayInfo(client);
List<GetPlayInfoResponse.PlayInfo> playInfoList = response.getPlayInfoList();
//播放地址
for (GetPlayInfoResponse.PlayInfo playInfo : playInfoList) {
    //这里要重点强调通过这个方法我们拿到的是我们加过水印之后的地址,如果不使用这个方法则拿到的是多个地址
if(playInfo.getFormat().equals("mp4")){

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");
}
/*获取播放地址函数*///这里面的setVideoId是我们当时上传的时候保存的
public static GetPlayInfoResponse getPlayInfo(DefaultAcsClient client) throws Exception {
GetPlayInfoRequest request = new GetPlayInfoRequest();
request.setVideoId("******************************");
return client.getAcsResponse(request);
}
public static DefaultAcsClient initVodClient(String accessKeyId, String accessKeySecret) throws ClientException {
String regionId = "cn-beijing"; // 点播服务接入区域
DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
DefaultAcsClient client = new DefaultAcsClient(profile);
return client;
}

版权声明:本文为zhao-hao原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/zhao-hao/p/12482572.html