-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
100 lines (79 loc) · 2.52 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
import PLAYLIST from "./data/music-data.js";
import { shuffle } from "./utils/shuffle.js";
import { getSettings, setSettings } from "./utils/localStorage.js";
import { changeColorSchemeToBnw, changeColorSchemeToDefault, changeColorSchemeToPastel, changeColorSchemeToWashout } from "./settings/settings.js";
const musicPlayer = document.getElementById('music-player');
const playBtn = document.getElementById('play-pause');
const previousBtn = document.getElementById('previous-track');
const nextBtn = document.getElementById('next-track');
let current_path = "";
const shuffledIndex = shuffle();
let settings = getSettings();
if( settings === null){
setSettings();
}
let shuffled_boolean = settings.shuffle;
let playlist = settings.playlist;
let color_Scheme = settings.scheme;
let current_song = 0;
let trackPlaying = false;
setScheme(color_Scheme, 'play');
function setScheme(str, playPauseToggle){
if( str === 'default' ){
changeColorSchemeToDefault(playPauseToggle);
}
if( str === 'washedout' ){
changeColorSchemeToWashout(playPauseToggle);
}
if( str === 'blackandwhite' ){
changeColorSchemeToBnw(playPauseToggle);
}
if( str === 'pastel' ){
changeColorSchemeToPastel(playPauseToggle);
}
}
setTrack(current_song);
playBtn.addEventListener('click', () => {
if (trackPlaying === false) {
playTrack();
} else { pauseTrack(); }
})
nextBtn.addEventListener('click', nextTrack);
previousBtn.addEventListener('click',previousTrack);
musicPlayer.addEventListener('ended', nextTrack);
function setTrack(song_index){
if (shuffled_boolean === true){
current_path = './assets/songs/' + `${PLAYLIST[playlist][shuffledIndex[song_index]].path}`;
musicPlayer.src = current_path;
}
else {
current_path = './assets/songs/' + `${PLAYLIST[playlist][song_index].path}`;
musicPlayer.src = current_path;
}
}
function nextTrack() {
if (current_song < PLAYLIST[playlist].length -1) {
current_song +=1;
} else {current_song = 0;
}
setTrack(current_song);
playTrack();
}
function previousTrack() {
if (current_song > 0 ) {
current_song -= 1; console.log(current_song);
} else {current_song = PLAYLIST[playlist].length -1; console.log(current_song);
}
setTrack(current_song);
playTrack();
}
function playTrack() {
musicPlayer.play();
trackPlaying = true;
setScheme(color_Scheme, 'pause');
}
function pauseTrack() {
musicPlayer.pause();
trackPlaying = false;
setScheme(color_Scheme, 'play');
}