-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayList.js
More file actions
executable file
·101 lines (75 loc) · 2.14 KB
/
PlayList.js
File metadata and controls
executable file
·101 lines (75 loc) · 2.14 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
93
94
95
96
97
98
99
100
101
/**
* Created by john on 05/06/15.
*/
var PlayList = {
id: null,
name: 'nameDefault',
curSong: 0,
selector: null,
list: [],
getTotalSongs: function total_songs(){
return this.list;
},
addSong: function add_song_to_list(song){
this.list.push(song);
// console.log('' + this.name + ', song=' + song.name);
if(this.list.length > 1) {
this.list = this.list.sort(function compareFunction(a, b) {
return (a.name).localeCompare(b.name);
});
}
},
updatePlayStatus: function update_play_satus(flag){
if(flag){
document.querySelector(this.selector).classList.add('playing');
}else{
document.querySelector(this.selector).classList.remove('playing');
}
},
removeSong: function remove_song_to_list(song){
for(var i=0; i < this.list.length; i++){
var item = this.list[i];
if(item.id = song.id){
this.list.slice(i,i+1);
}
}
},
getSong: function get_song(index){
if(!isNaN(index) && index <= this.list.length){
this.curSong = index;
}else{
this.curSong = 0;
}
return this.list[this.curSong];
},
getNextSong: function get_next_song(){
if(!isNaN(this.curSong) && this.curSong < this.list.length-1){
this.curSong++;
return this.list[this.curSong];
}else{
this.curSong = 0;
return this.list[this.curSong];
}
},
getCurrentSong: function get_current_song(){
return this.list[this.curSong];
},
getPrevSong: function get_prev_song(){
if(!isNaN(this.curSong) && this.curSong >0){
this.curSong--;
return this.list[this.curSong];
}else{
this.curSong = this.list.length-1;
return this.list[this.curSong];
}
},
getLength: function get_length(){
return this.list.length;
},
get: function (attr){
return this[attr];
},
set: function(attr, value){
this[attr] = value;
}
}