| @@ -93,7 +93,15 @@ public class VideoController extends BaseController { | |||||
| public ResultData upload(@RequestParam("file") MultipartFile multiReq,@RequestParam Map<String, String> param) { | public ResultData upload(@RequestParam("file") MultipartFile multiReq,@RequestParam Map<String, String> param) { | ||||
| try { | try { | ||||
| String title = param.get("title"); | String title = param.get("title"); | ||||
| VideUploadResult result = videoFactory.getExcutor(videoType).uploadLocalVideo(title, multiReq.getInputStream()); | |||||
| int dot = multiReq.getOriginalFilename().lastIndexOf('.'); | |||||
| String fileFormat = ""; | |||||
| if (dot >= 0) { | |||||
| fileFormat = multiReq.getOriginalFilename().substring(dot, multiReq.getOriginalFilename().length()); | |||||
| } | |||||
| if(!fileFormat.endsWith("mp4")){ | |||||
| return new ResultData(ErrorCode.PICTURE_ENDWIDTH_ERROR); | |||||
| } | |||||
| VideUploadResult result = videoFactory.getExcutor(videoType).uploadLocalVideo(title, multiReq.getInputStream(),fileFormat); | |||||
| return new ResultData(result); | return new ResultData(result); | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||
| @@ -564,6 +564,7 @@ public enum ErrorCode{ | |||||
| PICTURE_ANALYZING_ERROR(40002, "您上传的图片无法解析,请检查"), | PICTURE_ANALYZING_ERROR(40002, "您上传的图片无法解析,请检查"), | ||||
| PICTURE_SIZE_CUSTOMIZE(40003, "图片超过大小限制"), | PICTURE_SIZE_CUSTOMIZE(40003, "图片超过大小限制"), | ||||
| PICTURE_W_H_CUSTOMIZE(40004, "图片不符合宽高限制"), | PICTURE_W_H_CUSTOMIZE(40004, "图片不符合宽高限制"), | ||||
| PICTURE_ENDWIDTH_ERROR(40005, "格式不正确"), | |||||
| /** | /** | ||||
| * 电费生成配置 | * 电费生成配置 | ||||
| @@ -53,7 +53,15 @@ public class VideoController extends BaseController { | |||||
| public ResultData upload(@RequestParam("file") MultipartFile multiReq,@RequestParam Map<String, String> param) { | public ResultData upload(@RequestParam("file") MultipartFile multiReq,@RequestParam Map<String, String> param) { | ||||
| try { | try { | ||||
| String title = param.get("title"); | String title = param.get("title"); | ||||
| VideUploadResult result = videoFactory.getExcutor(videoType).uploadLocalVideo(title, multiReq.getInputStream()); | |||||
| int dot = multiReq.getOriginalFilename().lastIndexOf('.'); | |||||
| String fileFormat = ""; | |||||
| if (dot >= 0) { | |||||
| fileFormat = multiReq.getOriginalFilename().substring(dot, multiReq.getOriginalFilename().length()); | |||||
| } | |||||
| if(!fileFormat.endsWith("mp4")){ | |||||
| return new ResultData(ErrorCode.PICTURE_ENDWIDTH_ERROR); | |||||
| } | |||||
| VideUploadResult result = videoFactory.getExcutor(videoType).uploadLocalVideo(title, multiReq.getInputStream(),fileFormat); | |||||
| return new ResultData(result); | return new ResultData(result); | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||
| @@ -13,7 +13,7 @@ public interface VideoExcutor { | |||||
| */ | */ | ||||
| public VideUploadResult uploadLocalVideo(String title,String localFile); | public VideUploadResult uploadLocalVideo(String title,String localFile); | ||||
| public VideUploadResult uploadLocalVideo(String title,InputStream inputStream); | |||||
| public VideUploadResult uploadLocalVideo(String title,InputStream inputStream,String fileFormat); | |||||
| //ext,后缀名 | //ext,后缀名 | ||||
| public VideUploadResult uploadNetVideo(String title,String url,String ext); | public VideUploadResult uploadNetVideo(String title,String url,String ext); | ||||
| @@ -1,12 +1,11 @@ | |||||
| package com.iformall.video.aliyun; | package com.iformall.video.aliyun; | ||||
| import java.io.File; | |||||
| import java.io.FileInputStream; | |||||
| import java.io.FileNotFoundException; | |||||
| import java.io.IOException; | import java.io.IOException; | ||||
| import java.io.InputStream; | import java.io.InputStream; | ||||
| import java.util.List; | |||||
| import java.util.UUID; | import java.util.UUID; | ||||
| import com.aliyuncs.vod.model.v20170321.GetPlayInfoResponse; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.beans.factory.annotation.Qualifier; | import org.springframework.beans.factory.annotation.Qualifier; | ||||
| import org.springframework.data.redis.core.RedisTemplate; | import org.springframework.data.redis.core.RedisTemplate; | ||||
| @@ -51,6 +50,7 @@ public class AliyunVideoExcutor implements VideoExcutor { | |||||
| UploadVideoResponse response =AliyunVedioUpload.uploadVideo(config.getAccessKeyId(), config.getAccessKeySecret(),config.getRegionId(), title, localFile,redisTemplate); | UploadVideoResponse response =AliyunVedioUpload.uploadVideo(config.getAccessKeyId(), config.getAccessKeySecret(),config.getRegionId(), title, localFile,redisTemplate); | ||||
| if (response.isSuccess()) { | if (response.isSuccess()) { | ||||
| result.setVideoId(response.getVideoId()); | result.setVideoId(response.getVideoId()); | ||||
| setVideUploadResult(result,response.getVideoId()); | |||||
| result.setVideoUrl(getUrlByVeidoId(response.getVideoId())); | result.setVideoUrl(getUrlByVeidoId(response.getVideoId())); | ||||
| result.setSuccess(true); | result.setSuccess(true); | ||||
| }else { | }else { | ||||
| @@ -66,12 +66,29 @@ public class AliyunVideoExcutor implements VideoExcutor { | |||||
| return result; | return result; | ||||
| } | } | ||||
| private void setVideUploadResult(VideUploadResult result,String videoId) throws ClientException { | |||||
| result.setVideoId(videoId); | |||||
| GetPlayInfoResponse response = AliyunVedioServer.getPlayInfoResponse(config, videoId); | |||||
| if(response != null){ | |||||
| List<GetPlayInfoResponse.PlayInfo> playInfoList = response.getPlayInfoList(); | |||||
| //播放地址 | |||||
| for (GetPlayInfoResponse.PlayInfo playInfo : playInfoList) { | |||||
| result.setVideoUrl(playInfo.getPlayURL()); | |||||
| break; | |||||
| } | |||||
| GetPlayInfoResponse.VideoBase videoBase = response.getVideoBase(); | |||||
| result.setDuration(videoBase.getDuration()); | |||||
| result.setCoverURL(videoBase.getCoverURL()); | |||||
| result.setTitle(videoBase.getTitle()); | |||||
| } | |||||
| } | |||||
| @Override | @Override | ||||
| public VideUploadResult uploadLocalVideo(String title,InputStream inputStream) { | |||||
| public VideUploadResult uploadLocalVideo(String title,InputStream inputStream,String fileFormat) { | |||||
| VideUploadResult result = new VideUploadResult(); | VideUploadResult result = new VideUploadResult(); | ||||
| UploadStreamResponse response; | UploadStreamResponse response; | ||||
| try { | try { | ||||
| response = AliyunVedioUpload.uploadStream(config.getAccessKeyId(), config.getAccessKeySecret(),config.getRegionId(), title, UUID.randomUUID().toString().replace("-",""), inputStream,redisTemplate); | |||||
| response = AliyunVedioUpload.uploadStream(config.getAccessKeyId(), config.getAccessKeySecret(),config.getRegionId(), title, UUID.randomUUID().toString().replace("-","")+fileFormat, inputStream,redisTemplate); | |||||
| if (response.isSuccess()) { | if (response.isSuccess()) { | ||||
| result.setVideoId(response.getVideoId()); | result.setVideoId(response.getVideoId()); | ||||
| result.setVideoUrl(getUrlByVeidoId(response.getVideoId())); | result.setVideoUrl(getUrlByVeidoId(response.getVideoId())); | ||||
| @@ -41,4 +41,17 @@ public class AliyunVedioServer { | |||||
| } | } | ||||
| return null; | return null; | ||||
| } | } | ||||
| public static GetPlayInfoResponse getPlayInfoResponse(AliyunVideoConfig config, String videoId) throws ClientException { | |||||
| DefaultAcsClient client = initVodClient(config); | |||||
| GetPlayInfoResponse response = new GetPlayInfoResponse(); | |||||
| try { | |||||
| GetPlayInfoRequest request = new GetPlayInfoRequest(); | |||||
| request.setVideoId(videoId); | |||||
| return client.getAcsResponse(request); | |||||
| } catch (Exception e) { | |||||
| log.error("getVedioUrl error.",e); | |||||
| } | |||||
| return null; | |||||
| } | |||||
| } | } | ||||
| @@ -6,6 +6,9 @@ import lombok.Data; | |||||
| public class VideUploadResult { | public class VideUploadResult { | ||||
| private String videoId; | private String videoId; | ||||
| private String videoUrl; | private String videoUrl; | ||||
| private String coverURL;//视频封面 | |||||
| private String duration;//视频时长 | |||||
| private String title;//视频标题 | |||||
| private boolean success = false; | private boolean success = false; | ||||
| private String msg; | private String msg; | ||||
| } | } | ||||