-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom-player.js
58 lines (43 loc) · 1.53 KB
/
custom-player.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
// const media = document.querySelector('video');
const media = document.querySelector('audio');
// const controls = document.querySelector('.controls');
const mediaSource = document.getElementsByTagName('source')[0];
const play = document.querySelector('.play');
// const stop = document.querySelector('.stop');
// const rwd = document.querySelector('.rwd');
// const fwd = document.querySelector('.fwd');
// const timerWrapper = document.querySelector('.timer');
const timer = document.querySelector('.timer span');
const timerBar = document.querySelector('.timer div');
media.removeAttribute('controls');
// controls.style.visibility = 'visible';
play.addEventListener('click', playPauseMedia);
// stop.addEventListener('click', stopMedia);
// media.addEventListener('ended', stopMedia);
function playPauseMedia(tracks) {
if(media.paused) {
mediaSource.src = tracks.shift();
media.addEventListener('ended', () => { //when a song finished playing
if (tracks.length) {
media.pause();
mediaSource.src = tracks.shift();
media.load();
let tinyDelay = Math.random();
tinyDelay = Math.random();
// console.log(`Playing : ${mediaSource.src}`);
media.play();
}
});
media.load();
// console.log(`Playing : ${mediaSource.src}`);
media.play();
} else {
// play.setAttribute('data-icon','P');
media.pause();
}
}
function stopMedia() {
media.pause();
media.currentTime = 0;
// play.setAttribute('data-icon','P');
}