-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
187 lines (160 loc) · 5.14 KB
/
script.js
File metadata and controls
187 lines (160 loc) · 5.14 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
let videoPlayer=document.querySelector("video");
let videoRecordButton=document.querySelector("#record-video");
let constraint={video:true};
let capturedButton =document.querySelector("#click-image");
capturedButton.addEventListener("click",function(){
var audio = new Audio('shutter.wav');
audio.play();
capture();
});
let mediaRecorder;
let chunks=[];
let recordState=false;
// variable for timer
let timeInterval;
let minute=0,second=0;
videoRecordButton.addEventListener("click",function(e){
if(recordState==false){
mediaRecorder.start();
videoRecordButton.innerHTML="<img src=https://img.icons8.com/color/48/000000/stop.png/>";
recordState=true;
timeInterval=setInterval(function () {
if(second==60){
second=0;
minute+=1;
}
if(minute<10){
document.querySelector(".minute").innerText="0"+minute;
}
else{
document.querySelector(".minute").innerText=minute;
}
if(second<10){
document.querySelector(".second").innerText="0"+second;
}
else
{
document.querySelector(".second").innerText=second;
}
second+=1;
},1000)
}
else{//step4
recordState=false;
mediaRecorder.stop();
clearInterval(timeInterval)
second=0;
minute=0;
document.querySelector(".minute").innerText="00";
document.querySelector(".second").innerText="00";
videoRecordButton.innerHTML='<img src="https://img.icons8.com/flat-round/48/000000/record.png"/> ';
}
})
navigator.mediaDevices.getUserMedia(constraint)
.then(function(mediastream)
{
//console.log(mediastream.getVideoTracks()[0].getCapabilities()) return the functionality of the hardware
mediaRecorder=new MediaRecorder(mediastream);
videoPlayer.srcObject=mediastream
mediaRecorder.ondataavailable=function(e)
{
chunks.push(e.data)
console.log(typeof(e))
console.log(e.data)
}
mediaRecorder.onstop=function(e){
let blob=new Blob(chunks,{type:"video/mp4"})
chunks=[];
addData("video",blob);
// let a=document.createElement("a");
// a.href=url;
// a.download="temp.mp4";
// a.click();
}
})
//video-recording end
//image-capture start
function capture(){
let canvas=document.createElement("canvas");
canvas.height=videoPlayer.videoHeight;//height of video
canvas.width=videoPlayer.videoWidth;//width of video
let ctx=canvas.getContext("2d");//create a pen
//ZOOM IN AND ZOOM OUT SAVE
ctx.translate(canvas.width/2,canvas.height/2);
ctx.scale(zoom,zoom);
ctx.translate(-(canvas.width/2),-(canvas.height/2));
//END
ctx.drawImage(videoPlayer,0,0);
//draw the image whatever see on videoplayer at position at cordinate dx and dy destination x and y cordinate
if(filter!=""){
ctx.fillStyle=filter;
ctx.fillRect(0,0,canvas.width,canvas.height)
}
addData("image",canvas.toDataURL())
// let a=document.createElement("a");
// a.href=canvas.toDataURL();
// a.download="image.jpg";
// a.click();
}
//image capture end
//filter to the images
let filter="";
let allFilter=document.querySelectorAll(".filter");
for(i of allFilter){
i.addEventListener("click",function(e){
filter=e.currentTarget.style.backgroundColor;
addFilterToScreen(filter)
});
}
function addFilterToScreen(filter){
let prevFilter=document.querySelector(".screen-filter");
if(prevFilter){//if previousscreent filter exist than remove it
prevFilter.remove()
}
let filterScreen=document.createElement("div");
filterScreen.style.height=videoPlayer.offsetHeight+"px";//this will only give the height of video-player
filterScreen.style.width=videoPlayer.offsetWidth+"px";//this will only give the width of video-player
// filterScreen.style.position="fixed";
// filterScreen.style.top=0;
filterScreen.classList.add("screen-filter")
filterScreen.style.backgroundColor=filter;
document.querySelector(".filter-screen-parent").append(filterScreen)//if we dont put position fixed it will set below of video
}
//zoom in and zoom out
let zoom=1;
let zoomIn=document.querySelector(".zoom-in");
let zoomOut=document.querySelector(".zoom-out");
zoomIn.addEventListener("click",function(e){
if(zoom<2.0){
zoom+=0.1;
videoPlayer.style.transform=`scale(${zoom})`
}
})
zoomOut.addEventListener("click",function(){
if(zoom>1.0){
zoom-=0.1;
videoPlayer.style.transform=`scale(${zoom})`
}
})
let frame=document.querySelector(".frame");
frame.style["max-width"]=videoPlayer.offsetWidth;
//open and close modal
let openModal=document.querySelector(".show-gallary")
openModal.addEventListener("click",function(){
let modal=document.createElement("div")
modal.classList.add("modal");
modal.innerHTML=`
<div class="title">
<span style="margin-top:10px;display:inline-block;">Gallery</span>
<span class="close-modal" style="float:right;margin-top:10px; margin-right:10px;cursor:pointer;">X</span>
</div>
<div class="gallery">
</div>
`
document.querySelector("body").appendChild(modal)
getData()//fetch data
let closeModal=document.querySelector(".close-modal")//when modal is added then we can put eventlistner
closeModal.addEventListener("click",function(){
document.querySelector(".modal").remove();
})
})