| | |
| | | |
| | | package com.qxueyou.scc.teach.res.service.impl.resitem; |
| | | |
| | | import java.io.File; |
| | | import java.util.Date; |
| | | |
| | | import com.qxueyou.scc.sys.utils.VideoUtil; |
| | | import org.apache.commons.io.FileUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | @Service(value = "ResItemVideoService") |
| | | public class ResItemVideoService extends CommonAppService implements IResItemService { |
| | | |
| | | public static final String RES_VIDEO_CONVER_LST = "RES_VIDEO_CONVER_LST"; |
| | | public static final String RES_VIDEO_CONVER_LST = "RES_VIDEO_CONVER_LST"; |
| | | |
| | | @Autowired |
| | | IFileService fileService; |
| | | @Autowired |
| | | IFileService fileService; |
| | | |
| | | @Autowired |
| | | ICacheService cacheService; |
| | | @Autowired |
| | | ICacheService cacheService; |
| | | |
| | | @Override |
| | | public String add(String fileId, String name) { |
| | | @Value("${scc.resRootPath}") |
| | | String resRootPath; |
| | | |
| | | ResFile file = fileService.read(fileId); |
| | | String mediaVideoId = addVideoConverTask(file); |
| | | @Override |
| | | public String add(String fileId, String name) { |
| | | ResFile file = fileService.read(fileId); |
| | | String mediaVideoId = addVideoConverTask(file); |
| | | |
| | | ResItemVideo resVideo = new ResItemVideo(); |
| | | ResItemVideo resVideo = new ResItemVideo(); |
| | | |
| | | TraceUtils.setCreateTrace(resVideo); |
| | | TraceUtils.setCreateTrace(resVideo); |
| | | try { |
| | | resVideo.setFileId(fileId); |
| | | resVideo.setPlayTime((int) VideoUtil.getMp4Duration(resRootPath +"/"+ file.getPath())); |
| | | resVideo.setName(name); |
| | | resVideo.setMediaVideoId(mediaVideoId); |
| | | resVideo.setStatus(ResItemVideo.STATUS_LINEUP); |
| | | save(resVideo); |
| | | |
| | | resVideo.setFileId(fileId); |
| | | resVideo.setName(name); |
| | | resVideo.setMediaVideoId(mediaVideoId); |
| | | resVideo.setStatus(ResItemVideo.STATUS_LINEUP); |
| | | save(resVideo); |
| | | // 将mediaVideoId放进缓存 |
| | | cacheService.lstRightPush(RES_VIDEO_CONVER_LST, mediaVideoId); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | return resVideo.getVideoId(); |
| | | } |
| | | |
| | | // 将mediaVideoId放进缓存 |
| | | cacheService.lstRightPush(RES_VIDEO_CONVER_LST, mediaVideoId); |
| | | private String addVideoConverTask(ResFile file) { |
| | | |
| | | return resVideo.getVideoId(); |
| | | } |
| | | MediaVideo video = insertMediaVideo(file); |
| | | insertMediaVideoConverTask(video); |
| | | |
| | | private String addVideoConverTask(ResFile file) { |
| | | return video.getVideoId(); |
| | | |
| | | MediaVideo video = insertMediaVideo(file); |
| | | insertMediaVideoConverTask(video); |
| | | } |
| | | |
| | | return video.getVideoId(); |
| | | private MediaVideo insertMediaVideo(ResFile file) { |
| | | |
| | | } |
| | | MediaVideo video = new MediaVideo(); |
| | | |
| | | private MediaVideo insertMediaVideo(ResFile file) { |
| | | TraceUtils.setCreateTrace(video); |
| | | |
| | | MediaVideo video = new MediaVideo(); |
| | | try { |
| | | video.setDeleteFlag(false); |
| | | video.setPlayTime((int) VideoUtil.getMp4Duration(resRootPath +"/"+ file.getPath())); |
| | | video.setName(file.getFileName()); |
| | | video.setOrigUrl(file.getPath()); |
| | | video.setStatus(MediaVideo.STATUS_LINEUP); |
| | | video.setType(MediaVideo.MEDIA_VIDEO); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | TraceUtils.setCreateTrace(video); |
| | | save(video); |
| | | |
| | | video.setDeleteFlag(false); |
| | | video.setName(file.getFileName()); |
| | | video.setOrigUrl(file.getPath()); |
| | | video.setStatus(MediaVideo.STATUS_LINEUP); |
| | | video.setType(MediaVideo.MEDIA_VIDEO); |
| | | return video; |
| | | } |
| | | |
| | | save(video); |
| | | private Result insertMediaVideoConverTask(MediaVideo resVideo) { |
| | | |
| | | return video; |
| | | } |
| | | VideoConverTask task = new VideoConverTask(); |
| | | |
| | | private Result insertMediaVideoConverTask(MediaVideo resVideo) { |
| | | task.setCreateTime(new Date()); |
| | | task.setDeleteFlag(false); |
| | | task.setVideoId(resVideo.getVideoId()); |
| | | task.setVideoUrl(resVideo.getOrigUrl()); |
| | | task.setType(MediaVideo.MEDIA_VIDEO); |
| | | task.setPriority(5); |
| | | |
| | | VideoConverTask task = new VideoConverTask(); |
| | | save(task); |
| | | |
| | | task.setCreateTime(new Date()); |
| | | task.setDeleteFlag(false); |
| | | task.setVideoId(resVideo.getVideoId()); |
| | | task.setVideoUrl(resVideo.getOrigUrl()); |
| | | task.setType(MediaVideo.MEDIA_VIDEO); |
| | | task.setPriority(5); |
| | | return new Result(true); |
| | | } |
| | | |
| | | save(task); |
| | | @Override |
| | | public Result update(String id, String name) { |
| | | |
| | | return new Result(true); |
| | | } |
| | | ResItemVideo video = read(ResItemVideo.class, id); |
| | | |
| | | @Override |
| | | public Result update(String id, String name) { |
| | | TraceUtils.setUpdateTrace(video); |
| | | |
| | | ResItemVideo video = read(ResItemVideo.class, id); |
| | | video.setName(name); |
| | | |
| | | TraceUtils.setUpdateTrace(video); |
| | | save(video); |
| | | |
| | | video.setName(name); |
| | | return new Result(true, "success"); |
| | | } |
| | | |
| | | save(video); |
| | | @Override |
| | | public String readAccessPath(String resId, String attribute) { |
| | | |
| | | return new Result(true, "success"); |
| | | } |
| | | ResItemVideo resItemVideo = read(ResItemVideo.class, resId); |
| | | |
| | | @Override |
| | | public String readAccessPath(String resId, String attribute) { |
| | | |
| | | ResItemVideo resItemVideo = read(ResItemVideo.class, resId); |
| | | |
| | | if (resItemVideo != null && resItemVideo.getStatus() != ResItemVideo.STATUS_DRAFT) { |
| | | ResFile resFile = read(ResFile.class,resItemVideo.getFileId()); |
| | | return resFile.getPath(); |
| | | if (resItemVideo != null && resItemVideo.getStatus() != ResItemVideo.STATUS_DRAFT) { |
| | | ResFile resFile = read(ResFile.class, resItemVideo.getFileId()); |
| | | return resFile.getPath(); |
| | | // return null; |
| | | } |
| | | } |
| | | |
| | | MediaVideo video = read(MediaVideo.class, resItemVideo.getMediaVideoId()); |
| | | MediaVideo video = read(MediaVideo.class, resItemVideo.getMediaVideoId()); |
| | | |
| | | if (video == null) { |
| | | return null; |
| | | } |
| | | if (video == null) { |
| | | return null; |
| | | } |
| | | |
| | | return JSONObject.toJSONString(CollectionUtils.newObjectMap("hd",video.getAndroidHD(), "sd", video.getAndroidSD(), "ld", video.getAndroidLD(), "path",StringUtils.isNotEmpty(video.getAndroidHD()) ? video.getAndroidHD() |
| | | : StringUtils.isNotEmpty(video.getAndroidSD()) ? video.getAndroidSD() : video.getAndroidLD())); |
| | | return JSONObject.toJSONString(CollectionUtils.newObjectMap("hd", video.getAndroidHD(), "sd", video.getAndroidSD(), "ld", video.getAndroidLD(), "path", StringUtils.isNotEmpty(video.getAndroidHD()) ? video.getAndroidHD() |
| | | : StringUtils.isNotEmpty(video.getAndroidSD()) ? video.getAndroidSD() : video.getAndroidLD())); |
| | | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public String getResItemType() { |
| | | return Res.FILE_TYPE_VIDEO; |
| | | } |
| | | @Override |
| | | public String getResItemType() { |
| | | return Res.FILE_TYPE_VIDEO; |
| | | } |
| | | |
| | | /** |
| | | * 定时器转码成功后 同步更新ResItemVideo的状态 |
| | | */ |
| | | @Scheduled(cron = "0/2 * * * * ?") // 每2秒执行一次 |
| | | public void doTimer() { |
| | | /** |
| | | * 定时器转码成功后 同步更新ResItemVideo的状态 |
| | | */ |
| | | @Scheduled(cron = "0/2 * * * * ?") // 每2秒执行一次 |
| | | public void doTimer() { |
| | | |
| | | String mediaVideoId = cacheService.lstLeftPop(RES_VIDEO_CONVER_LST); |
| | | String mediaVideoId = cacheService.lstLeftPop(RES_VIDEO_CONVER_LST); |
| | | |
| | | if (StringUtils.isBlank(mediaVideoId)) { |
| | | return; |
| | | } |
| | | if (StringUtils.isBlank(mediaVideoId)) { |
| | | return; |
| | | } |
| | | |
| | | MediaVideo mediaVideo = read(MediaVideo.class, mediaVideoId); |
| | | if (mediaVideo.getStatus() == MediaVideo.STATUS_DRAFT) { |
| | | if (mediaVideo.getType().equals("video")) { |
| | | ResItemVideo resItemVideo = findUnique( |
| | | "from ResItemVideo where deleteFlag is false and mediaVideoId = ?", |
| | | CollectionUtils.newList(mediaVideoId), ResItemVideo.class); |
| | | resItemVideo.setStatus(ResItemVideo.STATUS_DRAFT); |
| | | TraceUtils.setUpdateTrace(resItemVideo); |
| | | resItemVideo.setVideoSeconds(mediaVideo.getPlayTime()); |
| | | save(resItemVideo); |
| | | MediaVideo mediaVideo = read(MediaVideo.class, mediaVideoId); |
| | | if (mediaVideo.getStatus() == MediaVideo.STATUS_DRAFT) { |
| | | if (mediaVideo.getType().equals("video")) { |
| | | ResItemVideo resItemVideo = findUnique( |
| | | "from ResItemVideo where deleteFlag is false and mediaVideoId = ?", |
| | | CollectionUtils.newList(mediaVideoId), ResItemVideo.class); |
| | | resItemVideo.setStatus(ResItemVideo.STATUS_DRAFT); |
| | | TraceUtils.setUpdateTrace(resItemVideo); |
| | | resItemVideo.setVideoSeconds(mediaVideo.getPlayTime()); |
| | | save(resItemVideo); |
| | | |
| | | cacheService.lstRightPush(ResService.RES_TOUPDATE_CONVER_STATUS_LST, resItemVideo.getVideoId());// 将转码完成后的文件id放入缓存。 |
| | | return; |
| | | } else if (mediaVideo.getType().equals("audio")) { |
| | | ResItemAudio resItemAudio = findUnique( |
| | | "from ResItemAudio where deleteFlag is false and mediaVideoId = ?", |
| | | CollectionUtils.newList(mediaVideoId), ResItemAudio.class); |
| | | resItemAudio.setStatus(ResItemVideo.STATUS_DRAFT); |
| | | TraceUtils.setUpdateTrace(resItemAudio); |
| | | resItemAudio.setSeconds(mediaVideo.getPlayTime()); |
| | | save(resItemAudio); |
| | | cacheService.lstRightPush(ResService.RES_TOUPDATE_CONVER_STATUS_LST, resItemVideo.getVideoId());// 将转码完成后的文件id放入缓存。 |
| | | return; |
| | | } else if (mediaVideo.getType().equals("audio")) { |
| | | ResItemAudio resItemAudio = findUnique( |
| | | "from ResItemAudio where deleteFlag is false and mediaVideoId = ?", |
| | | CollectionUtils.newList(mediaVideoId), ResItemAudio.class); |
| | | resItemAudio.setStatus(ResItemVideo.STATUS_DRAFT); |
| | | TraceUtils.setUpdateTrace(resItemAudio); |
| | | resItemAudio.setSeconds(mediaVideo.getPlayTime()); |
| | | save(resItemAudio); |
| | | |
| | | cacheService.lstRightPush(ResService.RES_TOUPDATE_CONVER_STATUS_LST, resItemAudio.getAudioId());// 将转码完成后的文件id放入缓存。 |
| | | return; |
| | | } |
| | | cacheService.lstRightPush(ResService.RES_TOUPDATE_CONVER_STATUS_LST, resItemAudio.getAudioId());// 将转码完成后的文件id放入缓存。 |
| | | return; |
| | | } |
| | | |
| | | } |
| | | cacheService.lstRightPush(RES_VIDEO_CONVER_LST, mediaVideoId); |
| | | } |
| | | cacheService.lstRightPush(RES_VIDEO_CONVER_LST, mediaVideoId); |
| | | |
| | | } |
| | | } |
| | | } |