‘liusuyi’
2023-07-29 226b979027a05d371501d64f7ce040a6fe2a60e2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.ruoyi.media.service.impl;
 
import com.ruoyi.utils.tools.CmdUtils;
import com.sun.jna.Platform;
import org.springframework.stereotype.Component;
 
import javax.annotation.PostConstruct;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
 
/**
 * @Description:
 * @ClassName: webrtcService
 * @Author: 刘苏义
 * @Date: 2023年07月26日13:43:07
 * @Version: 1.0
 **/
@Component
public class WebrtcService {
    @PostConstruct
    public void init() {
        if (Platform.isWindows()) {
            String processName = "webrtc-streamer.exe"; // 替换为实际的exe程序名称
            String exePath = System.getProperty("user.dir") + File.separator + "lib" + File.separator + "webrtc" + File.separator + processName;
            List<String> cmd = new ArrayList<>();
            cmd.add(exePath);
            cmd.add("-H127.0.0.1:8000");
            cmd.add("-o");
            if (CmdUtils.isProcessRunning(processName)) {
                // 进程已经在运行,结束该进程
                CmdUtils.stopProcess(processName);
            }
            // 启动后台进程
             CmdUtils.commandStart(processName,cmd);
            // 启动cmd窗口
//            String[] command = {"cmd", "/c", "start", exePath, "-H127.0.0.1:8000", "-o"};
//            CmdUtils.commandStart(command);
        }
    }
}