-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
138 lines (114 loc) · 4.45 KB
/
main.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
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
// all variables
let topuPlayer = document.querySelectorAll('.topu-player');
let thumbCover = document.querySelectorAll('.thumb-cover');
let trackName = document.querySelectorAll('.track-name');
let playlistName = document.querySelectorAll('.playlist-name');
let albumName = document.querySelectorAll('.album-name');
let singerName = document.querySelectorAll('.singer-name');
let progressBar = document.querySelectorAll('.progress-bar');
let progressBarFill = document.querySelectorAll('.bar-fill');
let currentTime = document.querySelectorAll('.current-time');
let durationTime = document.querySelectorAll('.duration-time');
let resetAudio = document.querySelectorAll('.reset-audio');
let prevAudio = document.querySelectorAll('.prev-audio');
let backwardAudio = document.querySelectorAll('.backward-audio');
let playPause = document.querySelectorAll('.playPause-audio');
let forwardAudio = document.querySelectorAll('.forward-audio');
let nextAudio = document.querySelectorAll('.next-audio');
let toggleVolume = document.querySelectorAll('.toggle-volume');
let volumeControl = document.querySelectorAll('.volume-control');
let audioSetting = document.querySelectorAll('.audio-setting');
let addPlaylist = document.querySelectorAll('.add-playlist');
let reportAudio = document.querySelectorAll('.report-audio');
let shareAudio = document.querySelectorAll('.share-audio');
let audioSettingClose = document.querySelectorAll('.audio-setting-close');
let audioPanel = document.querySelectorAll('audio-panel')
audioPanel.crossOrigin = "anonymous";
// // Audio source
// // Create audio context
// // let audioCtx = new AudioContext() || new webkitAudioContext(); -- for safari
// let audioCtx = new AudioContext();
// // Create audio node so that the analyser can work with
// let source = audioCtx.createMediaElementSource(audioPanel);
// // Create analyser
// let analyser = audioCtx.createAnalyser();
// // Make 2d context
// let ctx = canvas.getContext("2d");
// // Make connections
// source.connect(analyser);
// source.connect(audioCtx.destination);
// // analyser.fftSize = 2048;
// analyser.smoothingTimeConstant = 0.6;
// analyser.fftSize = 512;
// // Buffer length
// let bufferLength = analyser.frequencyBinCount;
// let data = new Uint8Array(bufferLength);
// audio lists
let songs = [
{
"track": "Topu Special",
"playlist": "Episode 09",
"singer": "Topu",
"album": "Horror Developer",
"thumb": "assets/img/o1.jpg",
"cover": "",
"path": "assets/audio/01.pm3"
},
{
"track": "Topu Special",
"playlist": "Episode 10",
"singer": "Topu",
"album": "Horror Developer",
"thumb": "assets/img/o2.jpg",
"cover": "",
"path": "assets/audio/02.pm3"
}
]
// initial play
let songCounter = 1;
let maxSongs = songs.length;
singerName.innerText = `ashadul`;
console.log(singerName);
const loadSong = (songCounter) => {
audioPanel[0].src = `${songs[songCounter].path}`;
thumbCover[0].src = `${songs[songCounter].thumb}`;
trackName[0].innerText = `${songs[songCounter].track}`
playlistName[0].innerText = `${songs[songCounter].playlist}`
albumName.innerText = `${songs[songCounter].album}`
singerName.innerText = `${songs[songCounter].singer}`
// trackName.innerText = `${songs[songCounter].track}`
console.log('load song called', songCounter);
}
loadSong(songCounter);
// audio play pause
const togglePlay = (audio) => {
// playPause.forEach((btn) => {
// })
}
let x = 0;
// console.log(playPause);
playPause.forEach((btn) => {
// console.log(btn);
// let play = btn.querySelector('.play')
// console.log(play);
// play.classList.remove('show')
// play.classList.add('hide')
btn.addEventListener('click', () => {
if (x === 0) {
x++;
btn.querySelector('.play').classList.remove('show')
btn.querySelector('.play').classList.add('hide')
btn.querySelector('.pause').classList.remove('hide')
btn.querySelector('.pause').classList.add('show')
} else {
x--;
btn.querySelector('.play').classList.add('show')
btn.querySelector('.play').classList.remove('hide')
btn.querySelector('.pause').classList.add('hide')
btn.querySelector('.pause').classList.remove('show')
}
})
})
// playPause.addEventListener('click', () => {
// playPause.querySelector('play').removeClassList('show').addClassList('hide')
// })