liusuyi
2023-07-28 2c97f9adf61f846edbce4ef458400416f0003ff8
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.ruoyi.media.service.impl;
 
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 exePath = System.getProperty("user.dir") + File.separator + "lib" + File.separator + "webrtc" + File.separator + "setup.bat";
            // String[] cmd = {"cmd", "/c", "start", exePath};
            String exePath = System.getProperty("user.dir") + File.separator + "lib" + File.separator + "webrtc" + File.separator + "webrtc-streamer.exe";
            List<String> cmd = new ArrayList<>();
            cmd.add(exePath);
            cmd.add("-o");
            cmd.add("-H127.0.0.1:8000");
            commandStart(cmd);
        }
    }
    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();
        }
    }
}