-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
69 lines (59 loc) · 1.92 KB
/
script.js
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
function $(selector) {
return document.querySelector(selector);
}
//Selecting all required selectors
const preview = $(".preview");
const playBtn = $(".play-pause");
const stop = $(".stop");
const player = $(".player");
const spinner = $(".audio-style");
const showMediaName = $(".togglebar .showname");
$("#fileInput").addEventListener("change", Player);
function Player() {
let file = this.files[0];
playBtn.classList.remove("fa-play");
playBtn.classList.add("fa-pause");
spinner.style.animation = " spin .5s ease-in forwards infinite";
console.log(playBtn.className);
if (file.type.indexOf("mp3") > 0) {
spinner.style.display = "block";
} else {
spinner.style.display = "none";
}
showMediaName.innerHTML = file.name;
let fileReader = new FileReader();
console.log(file);
fileReader.onload = function(event) {
let dataUrl = event.target.result;
preview.src = dataUrl;
};
if (preview.src != "") fileReader.readAsDataURL(file);
//$(".controls").style.bottom = "-100%";
}
function pausePlay() {
if (playBtn.classList.contains("fa-pause")) {
playBtn.classList.remove("fa-pause");
playBtn.classList.add("fa-play");
preview.pause();
spinner.style.animation = "none";
} else if (playBtn.classList.contains("fa-play")) {
playBtn.classList.remove("fa-play");
playBtn.classList.add("fa-pause");
preview.play();
spinner.style.animation = " spin .5s ease-in forwards infinite";
}
}
function stopPlay() {
preview.src = "";
preview.duration = 0;
playBtn.classList.remove("fa-pause");
playBtn.classList.add("fa-play");
spinner.style.display = "none";
showMediaName.innerHTML = "";
}
playBtn.addEventListener("click", pausePlay);
stop.addEventListener("click", stopPlay);
$("video").addEventListener("click", function() {
preview.pause();
});
//if (preview.src == "")