视频设置

This commit is contained in:
乐天 2018-12-11 22:34:27 +08:00
parent 29e8dc5241
commit 5b556b81f6
2 changed files with 82 additions and 0 deletions

View File

@ -0,0 +1,43 @@
package com.ruoyi.courseware.controller;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/train/courseware/video")
public class VideoController {
@GetMapping("")
public GetVideoPlayAuthResponse authority(){
DefaultProfile profile = DefaultProfile.getProfile("cn-shanghai", "LTAIo1i5PQB4pFme", "NyiVe3pqbVOMnwMQxnOkV39KrTx2jR");
DefaultAcsClient client = new DefaultAcsClient(profile);
GetVideoPlayAuthResponse response = getVideoPlayAuth(client);
System.out.println(response.getPlayAuth());
System.out.println(response.getVideoMeta());
return response;
}
private GetVideoPlayAuthResponse getVideoPlayAuth(DefaultAcsClient client) {
GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
request.setVideoId("ID3dbb151b73c34b678efff61d3d50d999");
GetVideoPlayAuthResponse response = null;
try {
response = client.getAcsResponse(request);
} catch (ServerException e) {
throw new RuntimeException("GetVideoPlayAuthRequest Server failed");
} catch (ClientException e) {
throw new RuntimeException("GetVideoPlayAuthRequest Client failed");
}
response.getPlayAuth(); // 播放凭证
response.getVideoMeta(); // 视频Meta信息
return response;
}
}

View File

@ -0,0 +1,39 @@
package com.ruoyi.courseware.utils;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;
public class VideoUtils {
// 设置AccessKey ID和AccessKey secret
private static String access_key_id = "LTAILL4H4JcoUJdf";
private static String access_key_secret = "6TtJ1MD7ueolOXWjx0VhaseX6nkPVe ";
public static void main(String[] args) {
// 点播服务所在的地域中国大陆地域请填cn-shanghai
DefaultProfile profile = DefaultProfile.getProfile("cn-shanghai", access_key_id, access_key_secret);
DefaultAcsClient client = new DefaultAcsClient(profile);
// 传入视频ID
GetVideoPlayAuthResponse response = getVideoPlayAuth(client, "3dbb151b73c34b678efff61d3d50d999");
System.out.println(response.getPlayAuth());
}
private static GetVideoPlayAuthResponse getVideoPlayAuth(DefaultAcsClient client, String videoId) {
GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
request.setVideoId(videoId);
GetVideoPlayAuthResponse response = null;
try {
response = client.getAcsResponse(request);
} catch (ServerException e) {
throw new RuntimeException("GetVideoPlayAuthRequest Server failed");
} catch (ClientException e) {
throw new RuntimeException("GetVideoPlayAuthRequest Client failed");
}
return response;
}
}