diff --git a/src/main/java/com/genersoft/iot/vmp/service/ICloudRecordService.java b/src/main/java/com/genersoft/iot/vmp/service/ICloudRecordService.java index 87798a08..83b1b151 100755 --- a/src/main/java/com/genersoft/iot/vmp/service/ICloudRecordService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/ICloudRecordService.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson2.JSONArray; import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; import com.genersoft.iot.vmp.media.zlm.dto.hook.OnRecordMp4HookParam; import com.genersoft.iot.vmp.service.bean.CloudRecordItem; +import com.genersoft.iot.vmp.service.bean.DownloadFileInfo; import com.github.pagehelper.PageInfo; import java.util.List; @@ -50,4 +51,8 @@ public interface ICloudRecordService { */ int changeCollectById(Integer recordId, boolean result); + /** + * 获取播放地址 + */ + DownloadFileInfo getPlayUrlPath(Integer recordId); } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/CloudRecordServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/CloudRecordServiceImpl.java index d9d6fe30..c9ed173a 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/CloudRecordServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/CloudRecordServiceImpl.java @@ -11,8 +11,10 @@ import com.genersoft.iot.vmp.media.zlm.dto.hook.OnRecordMp4HookParam; import com.genersoft.iot.vmp.service.ICloudRecordService; import com.genersoft.iot.vmp.service.IMediaServerService; import com.genersoft.iot.vmp.service.bean.CloudRecordItem; +import com.genersoft.iot.vmp.service.bean.DownloadFileInfo; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.dao.CloudRecordServiceMapper; +import com.genersoft.iot.vmp.utils.CloudRecordUtils; import com.genersoft.iot.vmp.utils.DateUtil; import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; import com.github.pagehelper.PageHelper; @@ -226,4 +228,15 @@ public class CloudRecordServiceImpl implements ICloudRecordService { public int changeCollectById(Integer recordId, boolean result) { return cloudRecordServiceMapper.changeCollectById(result, recordId); } + + @Override + public DownloadFileInfo getPlayUrlPath(Integer recordId) { + CloudRecordItem recordItem = cloudRecordServiceMapper.queryOne(recordId); + if (recordItem == null) { + throw new ControllerException(ErrorCode.ERROR400.getCode(), "资源不存在"); + } + String filePath = recordItem.getFilePath(); + MediaServerItem mediaServerItem = mediaServerService.getOne(recordItem.getMediaServerId()); + return CloudRecordUtils.getDownloadFilePath(mediaServerItem, filePath); + } } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java index 7ca07eee..2d94f300 100755 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java @@ -32,6 +32,7 @@ import com.genersoft.iot.vmp.service.bean.*; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.IVideoManagerStorage; import com.genersoft.iot.vmp.storager.dao.CloudRecordServiceMapper; +import com.genersoft.iot.vmp.utils.CloudRecordUtils; import com.genersoft.iot.vmp.utils.DateUtil; import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; import gov.nist.javax.sip.message.SIPResponse; @@ -728,7 +729,7 @@ public class PlayServiceImpl implements IPlayService { logger.info("[录像下载] 收到录像写入磁盘消息内容: " + hookParam); OnRecordMp4HookParam recordMp4HookParam = (OnRecordMp4HookParam)hookParam; String filePath = recordMp4HookParam.getFile_path(); - DownloadFileInfo downloadFileInfo = getDownloadFilePath(mediaServerItem, filePath); + DownloadFileInfo downloadFileInfo = CloudRecordUtils.getDownloadFilePath(mediaServerItem, filePath); InviteInfo inviteInfoForNew = inviteStreamService.getInviteInfo(inviteInfo.getType(), inviteInfo.getDeviceId() , inviteInfo.getChannelId(), inviteInfo.getStream()); inviteInfoForNew.getStreamInfo().setDownLoadFilePath(downloadFileInfo); @@ -824,21 +825,6 @@ public class PlayServiceImpl implements IPlayService { return inviteInfo.getStreamInfo(); } - private DownloadFileInfo getDownloadFilePath(MediaServerItem mediaServerItem, String filePath) { - DownloadFileInfo downloadFileInfo = new DownloadFileInfo(); - - String pathTemplate = "%s://%s:%s/index/api/downloadFile?file_path=" + filePath; - - downloadFileInfo.setHttpPath(String.format(pathTemplate, "http", mediaServerItem.getStreamIp(), - mediaServerItem.getHttpPort())); - - if (mediaServerItem.getHttpSSlPort() > 0) { - downloadFileInfo.setHttpsPath(String.format(pathTemplate, "https", mediaServerItem.getStreamIp(), - mediaServerItem.getHttpSSlPort())); - } - return downloadFileInfo; - } - private StreamInfo onPublishHandlerForDownload(MediaServerItem mediaServerItemInuse, HookParam hookParam, String deviceId, String channelId, String startTime, String endTime) { OnStreamChangedHookParam streamChangedHookParam = (OnStreamChangedHookParam) hookParam; StreamInfo streamInfo = onPublishHandler(mediaServerItemInuse, streamChangedHookParam, deviceId, channelId); diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/CloudRecordServiceMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/CloudRecordServiceMapper.java index 3724fecb..08f67ba9 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/CloudRecordServiceMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/CloudRecordServiceMapper.java @@ -112,4 +112,11 @@ public interface CloudRecordServiceMapper { "where call_id = #{callId}" + " ") List getListByCallId(@Param("callId") String callId); + + @Select(" ") + CloudRecordItem queryOne(@Param("id") Integer id); } diff --git a/src/main/java/com/genersoft/iot/vmp/utils/CloudRecordUtils.java b/src/main/java/com/genersoft/iot/vmp/utils/CloudRecordUtils.java new file mode 100644 index 00000000..8954bd7f --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/utils/CloudRecordUtils.java @@ -0,0 +1,22 @@ +package com.genersoft.iot.vmp.utils; + +import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; +import com.genersoft.iot.vmp.service.bean.DownloadFileInfo; + +public class CloudRecordUtils { + + public static DownloadFileInfo getDownloadFilePath(MediaServerItem mediaServerItem, String filePath) { + DownloadFileInfo downloadFileInfo = new DownloadFileInfo(); + + String pathTemplate = "%s://%s:%s/index/api/downloadFile?file_path=" + filePath; + + downloadFileInfo.setHttpPath(String.format(pathTemplate, "http", mediaServerItem.getStreamIp(), + mediaServerItem.getHttpPort())); + + if (mediaServerItem.getHttpSSlPort() > 0) { + downloadFileInfo.setHttpsPath(String.format(pathTemplate, "https", mediaServerItem.getStreamIp(), + mediaServerItem.getHttpSSlPort())); + } + return downloadFileInfo; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/cloudRecord/CloudRecordController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/cloudRecord/CloudRecordController.java index 41633cf8..dd7de2b6 100755 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/cloudRecord/CloudRecordController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/cloudRecord/CloudRecordController.java @@ -10,6 +10,7 @@ import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; import com.genersoft.iot.vmp.service.ICloudRecordService; import com.genersoft.iot.vmp.service.IMediaServerService; import com.genersoft.iot.vmp.service.bean.CloudRecordItem; +import com.genersoft.iot.vmp.service.bean.DownloadFileInfo; import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; import com.github.pagehelper.PageInfo; import io.swagger.v3.oas.annotations.Operation; @@ -237,4 +238,14 @@ public class CloudRecordController { return cloudRecordService.changeCollect(false, app, stream, mediaServerId, startTime, endTime, callId); } } + + @ResponseBody + @GetMapping("/play/path") + @Operation(summary = "获取播放地址") + @Parameter(name = "recordId", description = "录像记录的ID", required = true) + public DownloadFileInfo getPlayUrlPath( + @RequestParam(required = true) Integer recordId + ){ + return cloudRecordService.getPlayUrlPath(recordId); + } } diff --git a/web_src/src/components/CloudRecord.vue b/web_src/src/components/CloudRecord.vue index ca963e61..4a4a74b1 100755 --- a/web_src/src/components/CloudRecord.vue +++ b/web_src/src/components/CloudRecord.vue @@ -213,10 +213,26 @@ export default { console.log(row) this.chooseRecord = row; this.showPlayer = true; - let videoPath = row.filePath.substring(row.filePath.length - 25); - console.log(videoPath) - this.videoUrl = `${this.getFileBasePath(row)}/download/${row.app}/${row.stream}/${videoPath}` - console.log(this.videoUrl) + this.$axios({ + method: 'get', + url: `/api/cloud/record/play/path`, + params: { + recordId: row.id, + } + }).then((res) => { + console.log(res) + if (res.data.code === 0) { + if (location.protocol === "https:") { + this.videoUrl = res.data.data.httpsPath; + }else { + this.videoUrl = res.data.data.httpPath; + } + console.log(222 ) + console.log(this.videoUrl ) + } + }).catch((error) => { + console.log(error); + }); }, getFileBasePath(item) { let basePath = ""