Commit 92e5ed2e30126afc320ddf458c2653c4d41ef61d
1 parent
7e136c9a
优化前端云端录像的播放
Showing
7 changed files
with
80 additions
and
20 deletions
src/main/java/com/genersoft/iot/vmp/service/ICloudRecordService.java
| @@ -4,6 +4,7 @@ import com.alibaba.fastjson2.JSONArray; | @@ -4,6 +4,7 @@ import com.alibaba.fastjson2.JSONArray; | ||
| 4 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; | 4 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| 5 | import com.genersoft.iot.vmp.media.zlm.dto.hook.OnRecordMp4HookParam; | 5 | import com.genersoft.iot.vmp.media.zlm.dto.hook.OnRecordMp4HookParam; |
| 6 | import com.genersoft.iot.vmp.service.bean.CloudRecordItem; | 6 | import com.genersoft.iot.vmp.service.bean.CloudRecordItem; |
| 7 | +import com.genersoft.iot.vmp.service.bean.DownloadFileInfo; | ||
| 7 | import com.github.pagehelper.PageInfo; | 8 | import com.github.pagehelper.PageInfo; |
| 8 | 9 | ||
| 9 | import java.util.List; | 10 | import java.util.List; |
| @@ -50,4 +51,8 @@ public interface ICloudRecordService { | @@ -50,4 +51,8 @@ public interface ICloudRecordService { | ||
| 50 | */ | 51 | */ |
| 51 | int changeCollectById(Integer recordId, boolean result); | 52 | int changeCollectById(Integer recordId, boolean result); |
| 52 | 53 | ||
| 54 | + /** | ||
| 55 | + * 获取播放地址 | ||
| 56 | + */ | ||
| 57 | + DownloadFileInfo getPlayUrlPath(Integer recordId); | ||
| 53 | } | 58 | } |
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; | @@ -11,8 +11,10 @@ import com.genersoft.iot.vmp.media.zlm.dto.hook.OnRecordMp4HookParam; | ||
| 11 | import com.genersoft.iot.vmp.service.ICloudRecordService; | 11 | import com.genersoft.iot.vmp.service.ICloudRecordService; |
| 12 | import com.genersoft.iot.vmp.service.IMediaServerService; | 12 | import com.genersoft.iot.vmp.service.IMediaServerService; |
| 13 | import com.genersoft.iot.vmp.service.bean.CloudRecordItem; | 13 | import com.genersoft.iot.vmp.service.bean.CloudRecordItem; |
| 14 | +import com.genersoft.iot.vmp.service.bean.DownloadFileInfo; | ||
| 14 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | 15 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 15 | import com.genersoft.iot.vmp.storager.dao.CloudRecordServiceMapper; | 16 | import com.genersoft.iot.vmp.storager.dao.CloudRecordServiceMapper; |
| 17 | +import com.genersoft.iot.vmp.utils.CloudRecordUtils; | ||
| 16 | import com.genersoft.iot.vmp.utils.DateUtil; | 18 | import com.genersoft.iot.vmp.utils.DateUtil; |
| 17 | import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; | 19 | import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; |
| 18 | import com.github.pagehelper.PageHelper; | 20 | import com.github.pagehelper.PageHelper; |
| @@ -226,4 +228,15 @@ public class CloudRecordServiceImpl implements ICloudRecordService { | @@ -226,4 +228,15 @@ public class CloudRecordServiceImpl implements ICloudRecordService { | ||
| 226 | public int changeCollectById(Integer recordId, boolean result) { | 228 | public int changeCollectById(Integer recordId, boolean result) { |
| 227 | return cloudRecordServiceMapper.changeCollectById(result, recordId); | 229 | return cloudRecordServiceMapper.changeCollectById(result, recordId); |
| 228 | } | 230 | } |
| 231 | + | ||
| 232 | + @Override | ||
| 233 | + public DownloadFileInfo getPlayUrlPath(Integer recordId) { | ||
| 234 | + CloudRecordItem recordItem = cloudRecordServiceMapper.queryOne(recordId); | ||
| 235 | + if (recordItem == null) { | ||
| 236 | + throw new ControllerException(ErrorCode.ERROR400.getCode(), "资源不存在"); | ||
| 237 | + } | ||
| 238 | + String filePath = recordItem.getFilePath(); | ||
| 239 | + MediaServerItem mediaServerItem = mediaServerService.getOne(recordItem.getMediaServerId()); | ||
| 240 | + return CloudRecordUtils.getDownloadFilePath(mediaServerItem, filePath); | ||
| 241 | + } | ||
| 229 | } | 242 | } |
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
| @@ -32,6 +32,7 @@ import com.genersoft.iot.vmp.service.bean.*; | @@ -32,6 +32,7 @@ import com.genersoft.iot.vmp.service.bean.*; | ||
| 32 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | 32 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 33 | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; | 33 | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| 34 | import com.genersoft.iot.vmp.storager.dao.CloudRecordServiceMapper; | 34 | import com.genersoft.iot.vmp.storager.dao.CloudRecordServiceMapper; |
| 35 | +import com.genersoft.iot.vmp.utils.CloudRecordUtils; | ||
| 35 | import com.genersoft.iot.vmp.utils.DateUtil; | 36 | import com.genersoft.iot.vmp.utils.DateUtil; |
| 36 | import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; | 37 | import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; |
| 37 | import gov.nist.javax.sip.message.SIPResponse; | 38 | import gov.nist.javax.sip.message.SIPResponse; |
| @@ -728,7 +729,7 @@ public class PlayServiceImpl implements IPlayService { | @@ -728,7 +729,7 @@ public class PlayServiceImpl implements IPlayService { | ||
| 728 | logger.info("[录像下载] 收到录像写入磁盘消息内容: " + hookParam); | 729 | logger.info("[录像下载] 收到录像写入磁盘消息内容: " + hookParam); |
| 729 | OnRecordMp4HookParam recordMp4HookParam = (OnRecordMp4HookParam)hookParam; | 730 | OnRecordMp4HookParam recordMp4HookParam = (OnRecordMp4HookParam)hookParam; |
| 730 | String filePath = recordMp4HookParam.getFile_path(); | 731 | String filePath = recordMp4HookParam.getFile_path(); |
| 731 | - DownloadFileInfo downloadFileInfo = getDownloadFilePath(mediaServerItem, filePath); | 732 | + DownloadFileInfo downloadFileInfo = CloudRecordUtils.getDownloadFilePath(mediaServerItem, filePath); |
| 732 | InviteInfo inviteInfoForNew = inviteStreamService.getInviteInfo(inviteInfo.getType(), inviteInfo.getDeviceId() | 733 | InviteInfo inviteInfoForNew = inviteStreamService.getInviteInfo(inviteInfo.getType(), inviteInfo.getDeviceId() |
| 733 | , inviteInfo.getChannelId(), inviteInfo.getStream()); | 734 | , inviteInfo.getChannelId(), inviteInfo.getStream()); |
| 734 | inviteInfoForNew.getStreamInfo().setDownLoadFilePath(downloadFileInfo); | 735 | inviteInfoForNew.getStreamInfo().setDownLoadFilePath(downloadFileInfo); |
| @@ -824,21 +825,6 @@ public class PlayServiceImpl implements IPlayService { | @@ -824,21 +825,6 @@ public class PlayServiceImpl implements IPlayService { | ||
| 824 | return inviteInfo.getStreamInfo(); | 825 | return inviteInfo.getStreamInfo(); |
| 825 | } | 826 | } |
| 826 | 827 | ||
| 827 | - private DownloadFileInfo getDownloadFilePath(MediaServerItem mediaServerItem, String filePath) { | ||
| 828 | - DownloadFileInfo downloadFileInfo = new DownloadFileInfo(); | ||
| 829 | - | ||
| 830 | - String pathTemplate = "%s://%s:%s/index/api/downloadFile?file_path=" + filePath; | ||
| 831 | - | ||
| 832 | - downloadFileInfo.setHttpPath(String.format(pathTemplate, "http", mediaServerItem.getStreamIp(), | ||
| 833 | - mediaServerItem.getHttpPort())); | ||
| 834 | - | ||
| 835 | - if (mediaServerItem.getHttpSSlPort() > 0) { | ||
| 836 | - downloadFileInfo.setHttpsPath(String.format(pathTemplate, "https", mediaServerItem.getStreamIp(), | ||
| 837 | - mediaServerItem.getHttpSSlPort())); | ||
| 838 | - } | ||
| 839 | - return downloadFileInfo; | ||
| 840 | - } | ||
| 841 | - | ||
| 842 | private StreamInfo onPublishHandlerForDownload(MediaServerItem mediaServerItemInuse, HookParam hookParam, String deviceId, String channelId, String startTime, String endTime) { | 828 | private StreamInfo onPublishHandlerForDownload(MediaServerItem mediaServerItemInuse, HookParam hookParam, String deviceId, String channelId, String startTime, String endTime) { |
| 843 | OnStreamChangedHookParam streamChangedHookParam = (OnStreamChangedHookParam) hookParam; | 829 | OnStreamChangedHookParam streamChangedHookParam = (OnStreamChangedHookParam) hookParam; |
| 844 | StreamInfo streamInfo = onPublishHandler(mediaServerItemInuse, streamChangedHookParam, deviceId, channelId); | 830 | StreamInfo streamInfo = onPublishHandler(mediaServerItemInuse, streamChangedHookParam, deviceId, channelId); |
src/main/java/com/genersoft/iot/vmp/storager/dao/CloudRecordServiceMapper.java
| @@ -112,4 +112,11 @@ public interface CloudRecordServiceMapper { | @@ -112,4 +112,11 @@ public interface CloudRecordServiceMapper { | ||
| 112 | "where call_id = #{callId}" + | 112 | "where call_id = #{callId}" + |
| 113 | " </script>") | 113 | " </script>") |
| 114 | List<CloudRecordItem> getListByCallId(@Param("callId") String callId); | 114 | List<CloudRecordItem> getListByCallId(@Param("callId") String callId); |
| 115 | + | ||
| 116 | + @Select(" <script>" + | ||
| 117 | + "select *" + | ||
| 118 | + " from wvp_cloud_record " + | ||
| 119 | + "where id = #{id}" + | ||
| 120 | + " </script>") | ||
| 121 | + CloudRecordItem queryOne(@Param("id") Integer id); | ||
| 115 | } | 122 | } |
src/main/java/com/genersoft/iot/vmp/utils/CloudRecordUtils.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.utils; | ||
| 2 | + | ||
| 3 | +import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; | ||
| 4 | +import com.genersoft.iot.vmp.service.bean.DownloadFileInfo; | ||
| 5 | + | ||
| 6 | +public class CloudRecordUtils { | ||
| 7 | + | ||
| 8 | + public static DownloadFileInfo getDownloadFilePath(MediaServerItem mediaServerItem, String filePath) { | ||
| 9 | + DownloadFileInfo downloadFileInfo = new DownloadFileInfo(); | ||
| 10 | + | ||
| 11 | + String pathTemplate = "%s://%s:%s/index/api/downloadFile?file_path=" + filePath; | ||
| 12 | + | ||
| 13 | + downloadFileInfo.setHttpPath(String.format(pathTemplate, "http", mediaServerItem.getStreamIp(), | ||
| 14 | + mediaServerItem.getHttpPort())); | ||
| 15 | + | ||
| 16 | + if (mediaServerItem.getHttpSSlPort() > 0) { | ||
| 17 | + downloadFileInfo.setHttpsPath(String.format(pathTemplate, "https", mediaServerItem.getStreamIp(), | ||
| 18 | + mediaServerItem.getHttpSSlPort())); | ||
| 19 | + } | ||
| 20 | + return downloadFileInfo; | ||
| 21 | + } | ||
| 22 | +} |
src/main/java/com/genersoft/iot/vmp/vmanager/cloudRecord/CloudRecordController.java
| @@ -10,6 +10,7 @@ import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; | @@ -10,6 +10,7 @@ import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; | ||
| 10 | import com.genersoft.iot.vmp.service.ICloudRecordService; | 10 | import com.genersoft.iot.vmp.service.ICloudRecordService; |
| 11 | import com.genersoft.iot.vmp.service.IMediaServerService; | 11 | import com.genersoft.iot.vmp.service.IMediaServerService; |
| 12 | import com.genersoft.iot.vmp.service.bean.CloudRecordItem; | 12 | import com.genersoft.iot.vmp.service.bean.CloudRecordItem; |
| 13 | +import com.genersoft.iot.vmp.service.bean.DownloadFileInfo; | ||
| 13 | import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; | 14 | import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; |
| 14 | import com.github.pagehelper.PageInfo; | 15 | import com.github.pagehelper.PageInfo; |
| 15 | import io.swagger.v3.oas.annotations.Operation; | 16 | import io.swagger.v3.oas.annotations.Operation; |
| @@ -237,4 +238,14 @@ public class CloudRecordController { | @@ -237,4 +238,14 @@ public class CloudRecordController { | ||
| 237 | return cloudRecordService.changeCollect(false, app, stream, mediaServerId, startTime, endTime, callId); | 238 | return cloudRecordService.changeCollect(false, app, stream, mediaServerId, startTime, endTime, callId); |
| 238 | } | 239 | } |
| 239 | } | 240 | } |
| 241 | + | ||
| 242 | + @ResponseBody | ||
| 243 | + @GetMapping("/play/path") | ||
| 244 | + @Operation(summary = "获取播放地址") | ||
| 245 | + @Parameter(name = "recordId", description = "录像记录的ID", required = true) | ||
| 246 | + public DownloadFileInfo getPlayUrlPath( | ||
| 247 | + @RequestParam(required = true) Integer recordId | ||
| 248 | + ){ | ||
| 249 | + return cloudRecordService.getPlayUrlPath(recordId); | ||
| 250 | + } | ||
| 240 | } | 251 | } |
web_src/src/components/CloudRecord.vue
| @@ -213,10 +213,26 @@ export default { | @@ -213,10 +213,26 @@ export default { | ||
| 213 | console.log(row) | 213 | console.log(row) |
| 214 | this.chooseRecord = row; | 214 | this.chooseRecord = row; |
| 215 | this.showPlayer = true; | 215 | this.showPlayer = true; |
| 216 | - let videoPath = row.filePath.substring(row.filePath.length - 25); | ||
| 217 | - console.log(videoPath) | ||
| 218 | - this.videoUrl = `${this.getFileBasePath(row)}/download/${row.app}/${row.stream}/${videoPath}` | ||
| 219 | - console.log(this.videoUrl) | 216 | + this.$axios({ |
| 217 | + method: 'get', | ||
| 218 | + url: `/api/cloud/record/play/path`, | ||
| 219 | + params: { | ||
| 220 | + recordId: row.id, | ||
| 221 | + } | ||
| 222 | + }).then((res) => { | ||
| 223 | + console.log(res) | ||
| 224 | + if (res.data.code === 0) { | ||
| 225 | + if (location.protocol === "https:") { | ||
| 226 | + this.videoUrl = res.data.data.httpsPath; | ||
| 227 | + }else { | ||
| 228 | + this.videoUrl = res.data.data.httpPath; | ||
| 229 | + } | ||
| 230 | + console.log(222 ) | ||
| 231 | + console.log(this.videoUrl ) | ||
| 232 | + } | ||
| 233 | + }).catch((error) => { | ||
| 234 | + console.log(error); | ||
| 235 | + }); | ||
| 220 | }, | 236 | }, |
| 221 | getFileBasePath(item) { | 237 | getFileBasePath(item) { |
| 222 | let basePath = "" | 238 | let basePath = "" |