zengh
2022-05-16 63ad2c3598400370dd7da5534659fd7e768a0a4a
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<html>
 
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="renderer" content="webkit">
    <title>播放器</title>
    <style>
        #videoWin {
            width: 100%;
            height: 100%;
        }
    </style>
 
</head>
 
<body style="margin: 0;">
    <div style="width: 100%;height: 100%;position: absolute;">
        <div id="iwin" style="width: 100%;height: calc(100% - 200px);background:firebrick;">
            <div id="videoWin"></div>
        </div>
        <button onclick="getAccessToken();">getAccessToken</button>
        <!-- <button onclick="getLiveVideoList();">获取直播视频列表</button>
        <button onclick="getDeviceList();">获取设备列表</button> -->
        <button onclick="getCamerasList();">获取摄像头列表</button>
        <br />
        <span>设备获取列表demo</span>
        <select id="cameralist" style="min-width: 280px"></select>
        <button onclick="play();">播放测试</button>
        <br />
        <span>云台控制demo</span>
        <table>
            <tbody>
                <tr>
                    <td>
                        <button onmousedown="PtzMove(4);" onmouseup="PtzStop();">左上</button>
                    </td>
                    <td>
                        <button onmousedown="PtzMove(0);" onmouseup="PtzStop();">上</button>
                    </td>
                    <td>
                        <button onmousedown="PtzMove(6);" onmouseup="PtzStop();">右上</button>
                    </td>
                </tr>
                <tr>
                    <td>
                        <button onmousedown="PtzMove(2);" onmouseup="PtzStop();">左</button>
                    </td>
                    <td>
                        <button onmouseup="PtzStop();">O</button>
                    </td>
                    <td>
                        <button onmousedown="PtzMove(3);" onmouseup="PtzStop();">右</button>
                    </td>
                </tr>
                <tr>
                    <td>
                        <button onmousedown="PtzMove(5);" onmouseup="PtzStop();">左下</button>
                    </td>
                    <td>
                        <button onmousedown="PtzMove(1);" onmouseup="PtzStop();">下</button>
                    </td>
                    <td>
                        <button onmousedown="PtzMove(7);" onmouseup="PtzStop();">右下</button>
                    </td>
                </tr>
            </tbody>
        </table>
        <span>回放demo(hkDeviceControl.js文件里还有“根据时间获取历史影像”接口)</span>
        <br/>
        <span>时间:</span>
        <input id="begintime" type="text" placeholder="yyyyMMddhhmmss" /> - <input id="endtime" type="text" placeholder="yyyyMMddhhmmss" />
        <button onclick="playback();">回放</button>
        <button onclick="getPlaybackRecord();">查看回放记录</button>
    </div>
    <script type="text/javascript" src="js/ezuikit.js"></script>
    <script type="text/javascript" src="js/jquery-3.4.1.min.js"></script>
    <script type="text/javascript" src="js/hkDeviceControl.js"></script>
    <script>
            function play(obj) {
 
                //var url = $('#cameralist option:selected').val();
                //var accessToken = "at.262uxopt6ifa59wi62a92w19cf9jqzl3-5tow0h34ce-1qzgzxf-4ci8iqqrk";
                var index = $('#cameralist option:selected').val();
                var info = hkDevice.cameralist[index];
                var url = 'ezopen://open.ys7.com/' + info.deviceSerial + '/' + info.channelNo + '.live';
 
                var videoplay = new EZUIKit.EZUIPlayer({
                    id: 'videoWin',
                    autoplay: true,
                    url: url,
                    accessToken: hkDevice.accessToken,
                    decoderPath: '/videoPlay/',                //decoderPath:${window.YOUR_PATH};请在生产模式输入ezuikit.js的绝对路径
                    width: '600',
                    height: '400',
                    // handleError: handleError,
                    //handleSuccess: handleSuccess,
                });
            }
 
            function mppx(list) {
                var count = list.length;
                for (var i = 0; i < count - 1; i++) {
                    for (var j = 0; j < count - 1; j++) {
                        if (list[j].channelNo > list[j + 1].channelNo) {
                            var t = list[j];
                            list[j] = list[j + 1];
                            list[j + 1] = t;
                        }
                    }
                }
                return list;
            }
            var cameralist = [];
            var backRecord = [];
            function setCameralist(list) {
                list = mppx(list);
                console.log(list)
                var ht = "";
                for (var i = 0; i < list.length; i++) {
                    if(list[i].status == 1){
                    // ht += '<option value=' + i + '>' + (list[i].status == 1 ? "" : "[不可用]") + list[i].channelName + '</option>';
                       list[i].index = i;
                       cameralist.push(list[i])
                       //ht += '<option value=' + i + '>' +  list[i].channelName + '</option>';
                    }
                }
                var cameralist1 = cameralist.slice(0,6);
                for(var j=0;j<cameralist1.length;j++){
                    console.log(cameralist1[j].index)
                    getPlaybackRecord(cameralist1[j].index,cameralist1[j].channelName)
                }
 
                function sortNumber(a, b)
                {
                    return b.startTime - a.startTime
                }
                //document.getElementById("cameralist").innerHTML = ht;
                setTimeout(function(){
                    console.log(backRecord.sort(sortNumber))
                },1000)
            }
            //
            var hkDevice = new HkDevice("09c7be5c918542069e3f78737f2968a6","4c3ed3086fde15c5a28c975656882a1d");
 
            function getAccessToken(listFn) {
                hkDevice.getAccessToken(function (data) {
                        listFn&&listFn();
                });
            }
            // function getLiveVideoList() {
            //     hkDevice.getLiveVideoList(function (data) {
 
            //     });
            // }
            // function getDeviceList() {
            //     hkDevice.getDeviceList(function (data) {
 
            //     });
            // }
            function getCamerasList() {
                hkDevice.getCamerasList(function (data) {
                    setCameralist(data.data);
                });
            }
            function PtzMove(direction) {
                var index = $('#cameralist option:selected').val();
                var info = hkDevice.cameralist[index];
                hkDevice.setPtzTurn({
                    deviceSerial: info.deviceSerial,
                    channelNo: info.channelNo,
                    direction: direction,
                    speed: 1,//云台速度:0-慢,1-适中,2-快
                }, function (data) {
 
                });
 
            }
            function PtzStop() {
                var index = $('#cameralist option:selected').val();
                var info = hkDevice.cameralist[index];
                hkDevice.setPtzStop({
                    deviceSerial: info.deviceSerial,
                    channelNo: info.channelNo,
                }, function (data) {
 
                });
            }
            function getPlaybackRecord(index,name){
                //var index = $('#cameralist option:selected').val();
                var info = hkDevice.cameralist[index];
                var begin = document.getElementById("begintime").value;
                var end = document.getElementById("endtime").value;
                hkDevice.getPlaybackRecord({
                    deviceSerial:info.deviceSerial,
                    channelNo:info.channelNo,
                    startTime:begin,
                    endTime:end,
                },function(data){
                    //console.log(data);
                    if(data.data.length > 10){
                        var arr = data.data.slice(0,9);
                        for(var i=0;i<arr.length;i++){
                            arr[i].name = name;
                        }
                        
                        backRecord = backRecord.concat(arr);
                        console.log(backRecord);
                    }else{
                        for(var i=0;i<data.data.length;i++){
                            data.data[i].name = name;
                        }
                        //console.log(data.data);
                        //backRecord.push(data.data[i]);
                        backRecord = backRecord.concat(data.data);
                        console.log(backRecord);
                    }
                });
            }
 
            function playback() {
 
                var begin = document.getElementById("begintime").value;
                var end = document.getElementById("endtime").value;
                var index = $('#cameralist option:selected').val();
                var info = hkDevice.cameralist[index];
                var url = 'ezopen://open.ys7.com/' + info.deviceSerial + '/' + info.channelNo + '.rec?begin='+begin+'&end='+end;
 
                var videoplay = new EZUIKit.EZUIPlayer({
                    id: 'videoWin',
                    autoplay: true,
                    url: url,
                    accessToken: hkDevice.accessToken,
                    decoderPath: '',                //decoderPath:${window.YOUR_PATH};请在生产模式输入ezuikit.js的绝对路径
                    width: '600',
                    height: '400',
                    // handleError: handleError,
                    //handleSuccess: handleSuccess,
                });
            }
            //自动获取accessToken
            getAccessToken(getCamerasList);
            //自动获取摄像头列表
            //getCamerasList();
    </script>
</body>
 
</html>