-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
234 lines (148 loc) · 5.01 KB
/
script.js
File metadata and controls
234 lines (148 loc) · 5.01 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
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
const video = document.querySelector("video");
const videoContainer = document.querySelector(".video-container");
const recordBtn = document.querySelector(".record-btn");
const clickBtn = document.querySelector(".click-btn");
const ZoomInBtn = document.querySelector(".zoom-in-btn");
const ZoomOutBtn = document.querySelector(".zoom-out-btn");
const exampleDiv = document.querySelector(".example-div");
// error:- i was taking .filter-color but i should take .filter
const filterColor = document.querySelectorAll(".filter");
const filterOverlay = document.querySelector(".filter-overlay");
const timer = document.querySelector(".timer");
let colorOfImg = "transparent"
let seconds = 0;
let token;
let isRecording = false;
let isClicked = false;
let mediaRecorderObj;
let recordingDataArr = [];
// a1.1
const constraints = {
audio:true,
video:true
}
// A1.1 get video element and put stream on it
const mediaPromise = navigator.mediaDevices.getUserMedia(constraints);
mediaPromise.then((stream)=>{
video.srcObject = stream;
mediaRecorderObj = new MediaRecorder(stream);
mediaRecorderObj.addEventListener("dataavailable",(e)=>{
recordingDataArr.push(e.data);
})
mediaRecorderObj.addEventListener("stop",()=>{
let blob = new Blob(recordingDataArr,{type:'video/mp4'});
// let url = window.URL.createObjectURL(blob);
// let a = document.createElement("a");
// a.download = 'file.mp4';
// a.href = blob;
// a.click();
// a.remove();
addMediaToDatabase(blob,"video")
recordingDataArr= [];
})
}).catch((err)=>{
console.log(err);
})
//b1.1 make active record btn
recordBtn.addEventListener("click",()=>{
if (isRecording == false) {
mediaRecorderObj.start();
recordBtn.classList.add("animation-shrinkInOut");
recordBtn.innerHTML='<i class="fas fa-stop"></i>';
startTiming();
isRecording=true;
video.style.transform =`scale(${1})`
filterOverlay.style.display="none"
} else {
mediaRecorderObj.stop();
recordBtn.classList.remove("animation-shrinkInOut");
recordBtn.innerHTML='<i class="fas fa-video"></i>';
stopTiming();
isRecording=false;
video.style.transform =`scale(${scale})`
filterOverlay.style.display="block"
}
})
//b1.2make active click btn
clickBtn.addEventListener("click",()=>{
if (isClicked == false) {
clickBtn.style.animation = "shrinkInOut 1 1s"
isClicked=true;
} else {
clickBtn.style.animation = ""
isClicked=false;
}
})
let canvas = document.createElement("canvas");
//when click on on img btn photo clicked
clickBtn.addEventListener("click",()=>{
// canvas.style.border = "1px solid black"
// videoContainer.appendChild(canvas);
let tool = canvas.getContext("2d");
canvas.height = video.videoHeight;
canvas.width = video.videoWidth
tool.scale(scale, scale);
const x = (tool.canvas.width / scale - video.videoWidth) / 2;
const y = (tool.canvas.height / scale - video.videoHeight) / 2;
console.log(x, y);
tool.drawImage(video,x, y);
tool.fillStyle = colorOfImg;
tool.fillRect(x,y,canvas.width,canvas.height);
let url = canvas.toDataURL();
addMediaToDatabase(url,"img")
// let a = document.createElement("a");
// a.download = 'file.png';
// a.href = url;
// a.click();
exampleDiv.appendChild(canvas);
exampleDiv.style.animation = "shrinkInOut 1s "
setTimeout(()=>{
exampleDiv.style.animation = "none "
canvas.remove();
},1000)
// a.remove();
// canvas.remove();
// canvas.remove();
})
//zoom
let minScale = 1;
let maxScale = 1.7;
let scale=1;
ZoomInBtn.addEventListener("click",(e)=>{
if (scale > minScale) {
scale = scale-0.1
video.style.transform = `scale(${scale})`;
}
})
ZoomOutBtn.addEventListener("click",(e)=>{
if (scale < maxScale) {
scale = scale+0.1
video.style.transform = `scale(${scale})`;
}
})
//c1
let colorArr = [" #f3e5f54a","#a5d6a73d","#ad5d6d7a","#2195f323","transparent"];
for(let i=0; i<filterColor.length;i++){
filterColor[i].addEventListener("click",(e)=>{
colorOfImg = colorArr[i];
filterOverlay.style.backgroundColor = colorOfImg;
})
}
function startTiming() {
timer.style.display = "block";
fn = ()=>{
let hours = Number.parseInt(Number.parseInt(seconds)/3600)
let minutes = Number.parseInt(Number.parseInt(seconds)/60)%60;
let sec = Number.parseInt(Number.parseInt(seconds)%60);
timer.innerText = `${hours<10?`0${hours}`:hours}:${minutes<10?`0${minutes}`:minutes}:${seconds<10?`0${seconds}`:seconds}`;
seconds++;
}
token = setInterval(fn,1000);
}
function stopTiming() {
timer.style.display = "none";
setTimeout(()=>{
clearInterval(token)
},1000)
seconds = 0;
}