whycxzp
2024-12-31 44fad38cf4808c535c6d15f5366aa7cd09bfc3ee
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package com.whyc.service;
 
import com.whyc.dto.Response;
import com.whyc.util.ActionUtil;
import com.whyc.util.HttpUtil;
import org.springframework.stereotype.Service;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import static com.whyc.util.HttpUtil.urlEncode;
 
/**
 * 视频相关服务封装
 */
@Service
public class VideoService {
 
    /**
     * 获取视频流id
     * @return
     */
    public List<String> getVideoStreamIds() {
        Map<String, Object> params = new HashMap<>();//组合参数
        params.put("pageIndex", 1);
        params.put("pageSize", 1);
        String queryParams = urlEncode(params);
        String httpUrl ="http://192.168.10.133:9092/index/api/getMediaList";
        Response response = HttpUtil.doGet(httpUrl, queryParams);
        Integer httpResponseCode = response.getCode();
        String responseJson = (String) response.getData();
        if(httpResponseCode == 1) { //请求成功
            Response responseHttp = HttpUtil.getGson().fromJson(responseJson, Response.class);
            if(responseHttp.getCode() == 1) {
                //TODO 需要实际调试,目前返回的数据结构未确定
                return HttpUtil.getGson().fromJson(responseHttp.getData().toString(), List.class);
            }else{
                return null;
            }
        }else{
            return null;
        }
    }
 
    public void startRecord(String streamId){
        Map<String, Object> params = new HashMap<>();//组合参数
        params.put("secret", "TWSYFgYJOQWB4ftgeYut8DW4wbs7pQnj");
        params.put("type", 1);
        params.put("vhost", "__defaultVhost__");
        params.put("app", "rtp");
        params.put("stream", streamId);
        String queryParams = urlEncode(params);
        String httpUrl ="http://192.168.10.133:9092/index/api/startRecord";
        Response response = HttpUtil.doGet(httpUrl, queryParams);
        Integer code = response.getCode();
        String responseJson = (String) response.getData();
        if(code == 1) { //请求成功
            Response responseHttp = HttpUtil.getGson().fromJson(responseJson, Response.class);
            if(responseHttp.getCode() == 0 && responseHttp.getMsg().equals("success")) { //请求成功
            }else{
                System.out.println(responseHttp.getMsg());
            }
        }
 
    }
 
    public void stopRecord(String streamId){
        Map<String, Object> params = new HashMap<>();//组合参数
        params.put("secret", "TWSYFgYJOQWB4ftgeYut8DW4wbs7pQnj");
        params.put("type", 1);
        params.put("vhost", "__defaultVhost__");
        params.put("app", "rtp");
        params.put("stream", streamId);
        String queryParams = urlEncode(params);
        String httpUrl ="http://192.168.10.133:9092/index/api/stopRecord";
        Response response = HttpUtil.doGet(httpUrl, queryParams);
        Integer code = response.getCode();
        String responseJson = (String) response.getData();
        if(code == 1) { //请求成功
            Response responseHttp = HttpUtil.getGson().fromJson(responseJson, Response.class);
            if(responseHttp.getCode() == 0 && responseHttp.getMsg().equals("success")) { //请求成功
            }else{
                System.out.println(responseHttp.getMsg());
            }
        }
 
    }
 
}