-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.js
More file actions
93 lines (70 loc) · 1.97 KB
/
player.js
File metadata and controls
93 lines (70 loc) · 1.97 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
import audios from "./data.js";
import{path, secondsToMinutes} from "./utils.js";
import elements from "./playerElements.js";
export default{
audioData: audios,
currentAudio:{},
currentPlaying: 0,
isPlaying: false,
start(){
elements.get.call(this);
this.update();
},
play(){
this.isPlaying = true;
this.audio.play();
this.playPause.innerText="pause";
},
pause(){
this.isPlaying = false;
this.audio.pause();
this.playPause.innerText="play_arrow";
},
togglePlayPause(){
if(this.isPlaying ){
this.pause();
}
else{
this.play();
}
},
toggleMute(){
this.audio.muted = !this.audio.muted;
this.vol.innerText = this.audio.muted ? "volume_down" : "volume_up"
},
next(){
this.currentPlaying++;
if(this.currentPlaying == this.audioData.length){
this.restart();
}
this.update();
this.audio.play();
this.play();
},
setVolume(value){
this.audio.volume = value/100;
},
setSeek(value){
this.audio.currentTime = value;
},
timeUpdate(){
this.currentDuration.innerText = secondsToMinutes(this.audio.currentTime);
this.seekbar.value = this.audio.currentTime;
},
update(){
this.currentAudio = this.audioData[this.currentPlaying];
this.cover.style.background = `url('${path(
this.currentAudio.cover
)}') no-repeat center center / cover`;
this.title.innerText = this.currentAudio.title;
this.artist.innerHTML = this.currentAudio.artist;
elements.createAudioElement.call(this, path(this.currentAudio.file));
this.audio.onloadeddata = () =>{
elements.actions.call(this);
};
},
restart(){
this.currentPlaying = 0;
this.update();
}
};