| | |
| | | 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; |
| | |
| | | * @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("销毁mediaMtx"); |
| | | if (CmdUtils.isProcessRunning(processName)) { |
| | | // 进程已经在运行,结束该进程 |
| | | CmdUtils.stopProcess(processName); |
| | | } |
| | | } |
| | | |