From 67d965cb476bde49109a3773532c33dd9de60518 Mon Sep 17 00:00:00 2001
From: Administrator <1144154118@qq.com>
Date: 星期三, 09 八月 2023 13:30:02 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
ard-work/src/main/java/com/ruoyi/media/service/impl/MediaService.java | 45 ++++++++++++++++++++++++++++++---------------
1 files changed, 30 insertions(+), 15 deletions(-)
diff --git a/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaService.java b/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaService.java
index 3bdf604..d10da3b 100644
--- a/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaService.java
+++ b/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaService.java
@@ -15,6 +15,7 @@
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import java.io.BufferedReader;
import java.io.File;
@@ -33,33 +34,47 @@
* @Version: 1.0
**/
@Service
-@Slf4j
+@Slf4j(topic = "cmd")
public class MediaService implements IMediaService {
@Resource
MediaClient mediaClient;
@Value("${mediamtx.host}")
String mediamtxHost;
+ @Value("${mediamtx.enabled}")
+ Boolean mediamtxEnabled;
+
+ String processName = "mediamtx.exe";
@PostConstruct
public void initMediaMtx() {
- if (Platform.isWindows()) {
- String processName="mediamtx.exe";
- String exePath = System.getProperty("user.dir") + File.separator + "lib" + File.separator + "mediamtx" + File.separator + "mediamtx.exe";
- String ymlPath = System.getProperty("user.dir") + File.separator + "lib" + File.separator + "mediamtx" + File.separator + "mediamtx.yml";
+ if (mediamtxEnabled) {
+ if (Platform.isWindows()) {
+ String exePath = System.getProperty("user.dir") + File.separator + "lib" + File.separator + "mediamtx" + File.separator + "mediamtx.exe";
+ String ymlPath = System.getProperty("user.dir") + File.separator + "lib" + File.separator + "mediamtx" + File.separator + "mediamtx.yml";
- List<String> cmd = new ArrayList<>();
- cmd.add(exePath);
- cmd.add(ymlPath);
- if (CmdUtils.isProcessRunning(processName)) {
- // 杩涚▼宸茬粡鍦ㄨ繍琛岋紝缁撴潫璇ヨ繘绋�
- CmdUtils.stopProcess(processName);
- }
- // 鍚姩鍚庡彴杩涚▼
- CmdUtils.commandStart(processName,cmd);
- // 鍚姩cmd绐楀彛
+ List<String> cmd = new ArrayList<>();
+ cmd.add(exePath);
+ cmd.add(ymlPath);
+ if (CmdUtils.isProcessRunning(processName)) {
+ // 杩涚▼宸茬粡鍦ㄨ繍琛岋紝缁撴潫璇ヨ繘绋�
+ CmdUtils.stopProcess(processName);
+ }
+ // 鍚姩鍚庡彴杩涚▼
+ CmdUtils.commandStart(processName, cmd, null);
+ // 鍚姩cmd绐楀彛
// String[] command = {"cmd","/c","start",exePath,ymlPath};
// CmdUtils.commandStart(command);
+ }
+ }
+ }
+
+ @PreDestroy
+ public void destroyMediaMtx() {
+ log.info("閿�姣乵ediaMtx");
+ if (CmdUtils.isProcessRunning(processName)) {
+ // 杩涚▼宸茬粡鍦ㄨ繍琛岋紝缁撴潫璇ヨ繘绋�
+ CmdUtils.stopProcess(processName);
}
}
--
Gitblit v1.9.3