| | |
| | | import com.ruoyi.media.service.IMediaService; |
| | | import com.ruoyi.utils.forest.MediaClient; |
| | | import com.ruoyi.utils.tools.ArdTool; |
| | | import com.ruoyi.utils.tools.CmdUtils; |
| | | import com.sun.jna.Platform; |
| | | import io.minio.messages.Item; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | @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"; |
| | | // 构建启动命令,使用cmd /c start命令来启动可执行程序并显示命令提示符窗口 |
| | | // String[] cmd = {"cmd", "/c", "start", exePath,ymlPath}; |
| | | // ProcessBuilder processBuilder = new ProcessBuilder(cmd); |
| | | // processBuilder.redirectErrorStream(true); // 将错误输出重定向到标准输出 |
| | | // Process process = processBuilder.start(); |
| | | // 如果你想等待程序完成 |
| | | // int exitCode = process.waitFor(); |
| | | |
| | | List<String> cmd = new ArrayList<>(); |
| | | cmd.add(exePath); |
| | | cmd.add(ymlPath); |
| | | commandStart(cmd); |
| | | if (CmdUtils.isProcessRunning(processName)) { |
| | | // 进程已经在运行,结束该进程 |
| | | CmdUtils.stopProcess(processName); |
| | | } |
| | | // 启动后台进程 |
| | | CmdUtils.commandStart(processName,cmd); |
| | | // 启动cmd窗口 |
| | | // String[] command = {"cmd","/c","start",exePath,ymlPath}; |
| | | // CmdUtils.commandStart(command); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | public static void commandStart(List<String> command) { |
| | | command.forEach(v -> System.out.print(v + " ")); |
| | | System.out.println(); |
| | | System.out.println(); |
| | | ProcessBuilder builder = new ProcessBuilder(); |
| | | //正常信息和错误信息合并输出 |
| | | builder.redirectErrorStream(true); |
| | | builder.command(command); |
| | | //开始执行命令 |
| | | Process process = null; |
| | | try { |
| | | process = builder.start(); |
| | | //如果你想获取到执行完后的信息,那么下面的代码也是需要的 |
| | | // String line = ""; |
| | | // BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream())); |
| | | // while ((line = br.readLine()) != null) { |
| | | // System.out.println(line); |
| | | // } |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | @Override |
| | | public String addPath(String name, String rtspPath, String mode) { |
| | | String rtspUrl = "rtsp://" + mediamtxHost + ":7554/"; |