소스 검색

获取流列表接口修改

gao.qiang 1 년 전
부모
커밋
5c8078b0eb
1개의 변경된 파일31개의 추가작업 그리고 3개의 파일을 삭제
  1. 31 3
      business-service/src/main/java/com/ozs/utils/CameraUtil.java

+ 31 - 3
business-service/src/main/java/com/ozs/utils/CameraUtil.java

@@ -304,12 +304,26 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
      * @return
      */
     public static String getPlayFlv(String cameraCode, String channel) {
+        int maxRetries = 3;
+        int retryCount = 0;
+        boolean success = false;
+        JSONArray jsonArray = null;
         List<String> pathList = new ArrayList<>();
         String data = HttpUtils.sendGet(webUrl + "/rtsp/api/list");
         if (StringUtils.isNotEmpty(data)) {
             log.info("---------------data---" + data);
-            JSONArray jsonArray = JSONArray.parseArray(data);
-            log.info("---------------jsonArray---" + jsonArray);
+            while (!success && retryCount < maxRetries) {
+                try {
+                    jsonArray = JSONArray.parseArray(data);
+                    success = true;
+                } catch (Exception e) {
+                    e.printStackTrace();
+                    log.info("Exception caught: " + e.getMessage());
+                    // 增加重试计数
+                    retryCount++;
+                }
+            }
+                log.info("---------------jsonArray---" + jsonArray);
             if (!ObjectUtils.isEmpty(jsonArray)) {
                 for (int i = 0; i < jsonArray.size(); i++) {
                     JSONObject jsonObject = jsonArray.getJSONObject(i);
@@ -347,11 +361,25 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
     }
 
     public String heartbeatgetPlayFlv(String cameraCode, String channel, boolean type) {
+        int maxRetries = 3;
+        int retryCount = 0;
+        boolean success = false;
+        JSONArray jsonArray = null;
         List<String> pathList = new ArrayList<>();
         String data = HttpUtils.sendGet(webUrl + "/rtsp/api/list");
         log.info("data------------------>" + data);
         if (StringUtils.isNotEmpty(data)) {
-            JSONArray jsonArray = JSONArray.parseArray(data);
+            while (!success && retryCount < maxRetries) {
+                try {
+                    jsonArray = JSONArray.parseArray(data);
+                    success = true;
+                } catch (Exception e) {
+                    e.printStackTrace();
+                    log.info("Exception caught: " + e.getMessage());
+                    // 增加重试计数
+                    retryCount++;
+                }
+            }
             log.info("jsonArray------------------>" + jsonArray);
             if (!ObjectUtils.isEmpty(jsonArray)) {
                 for (int i = 0; i < jsonArray.size(); i++) {