Commit b11c57d4b5c9c3b62e2cbea0672d8b5b0235f966

Authored by lawrencehj
1 parent fa4b73cb

修正打包jar后snap路径问题,兼容windows路径

src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
... ... @@ -24,7 +24,6 @@ import gov.nist.javax.sip.stack.SIPDialog;
24 24 import org.slf4j.Logger;
25 25 import org.slf4j.LoggerFactory;
26 26 import org.springframework.beans.factory.annotation.Autowired;
27   -import org.springframework.beans.factory.annotation.Value;
28 27 import org.springframework.http.HttpStatus;
29 28 import org.springframework.http.ResponseEntity;
30 29 import org.springframework.stereotype.Service;
... ... @@ -32,13 +31,11 @@ import org.springframework.util.ResourceUtils;
32 31 import org.springframework.web.context.request.async.DeferredResult;
33 32  
34 33 import javax.sip.ClientTransaction;
35   -import javax.sip.Dialog;
36   -import javax.sip.header.CallIdHeader;
37 34 import javax.sip.message.Response;
38   -import java.io.File;
39 35 import java.io.FileNotFoundException;
40 36 import java.util.UUID;
41 37  
  38 +@SuppressWarnings(value = {"rawtypes", "unchecked"})
42 39 @Service
43 40 public class PlayServiceImpl implements IPlayService {
44 41  
... ... @@ -97,7 +94,20 @@ public class PlayServiceImpl implements IPlayService {
97 94 result.onCompletion(()->{
98 95 // 点播结束时调用截图接口
99 96 try {
100   - String path = ResourceUtils.getURL("classpath:").getPath()+"static/static/snap/";
  97 + String classPath = ResourceUtils.getURL("classpath:").getPath();
  98 + // System.out.println(classPath);
  99 + String path = classPath + "static/static/snap/";
  100 + if(classPath.contains("jar")) {
  101 + classPath = classPath.substring(0, classPath.lastIndexOf("."));
  102 + classPath = classPath.substring(0, classPath.lastIndexOf("/"));
  103 + path = classPath + "/snap/";
  104 + }
  105 + if (path.startsWith("file:")) {
  106 + path = path.substring(path.indexOf(":") + 1, path.length());
  107 + }
  108 + if(System.getProperty("os.name").contains("indows")) {
  109 + path = path.substring(1, path.length());
  110 + }
101 111 String fileName = deviceId + "_" + channelId + ".jpg";
102 112 ResponseEntity responseEntity = (ResponseEntity)result.getResult();
103 113 if (responseEntity != null && responseEntity.getStatusCode() == HttpStatus.OK) {
... ... @@ -109,7 +119,6 @@ public class PlayServiceImpl implements IPlayService {
109 119 zlmresTfulUtils.getSnap(flvUrl, 5, 1, path, fileName);
110 120 }
111 121 }
112   -
113 122 System.out.println(path);
114 123 } catch (FileNotFoundException e) {
115 124 e.printStackTrace();
... ...