New remove song function

This commit is contained in:
Michael 2017-12-15 15:03:52 -05:00
parent fa59380e4a
commit 82ca11d126
3 changed files with 62 additions and 2 deletions

2
dist/APlayer.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -846,6 +846,66 @@ class APlayer {
}
}
/**
* Remove song from playlist
*/
removeSong(indexOfSong) {
if (this.option.music[indexOfSong] != null) { // Check if song exists
const list = this.element.getElementsByClassName('aplayer-list')[0];
var oList = list.firstElementChild; // OL tag
var liList = []; // Holds the index of the LI tags
for (let i = 0; i < oList.childNodes.length; i++) {
if (oList.childNodes[i].tagName == 'LI') {
liList.push(i); //Adds the LI tag indexes to array
}
}
if (this.option.music[indexOfSong + 1] != null || this.option.music[indexOfSong - 1] != null) {
if (indexOfSong == this.playIndex) {
if (this.option.music[indexOfSong + 1] != null) { // Play next song if it exists. If not paused.
this.setMusic(indexOfSong + 1);
} else if (this.option.music[indexOfSong + 1] == null) { // Play previous song if it exists. If not paused.
this.setMusic(indexOfSong - 1);
}
this.playIndex = this.playIndex - 1
} else {
if (indexOfSong < this.playIndex) {
this.playIndex = this.playIndex - 1;
}
}
if (oList.childNodes[liList[indexOfSong + 1]] == null) {
var targetSong = oList.childNodes[liList[indexOfSong - 1]];
targetSong.childNodes[3].textContent = indexOfSong;
} else {
for (let i = 1; i < liList.length; i++) {
if (oList.childNodes[liList[indexOfSong + i]] != null) {
var targetSong = oList.childNodes[liList[indexOfSong + i]];
targetSong.childNodes[3].textContent = indexOfSong + i;
}
}
}
this.option.music.splice(indexOfSong, 1); // Delete song from music array
this.audios.splice(indexOfSong, 1); // Delete song from audios array (Has to be)
oList.childNodes[liList[indexOfSong]].remove();
if (this.option.music[0] != null && this.option.music[1] == null) {
this.multiple = false;
this.element.classList.remove('aplayer-withlist');
}
}
list.style.height = "";
} else {
console.error("ERROR: Song does not exist");
}
}
/**
* destroy this player
*/