Initial files for playlist structuring.
This commit is contained in:
parent
4dc5e64fa3
commit
f33196c013
28
src/player/Playlist.js
Normal file
28
src/player/Playlist.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import PlaylistSong from "./PlaylistSong";
|
||||||
|
|
||||||
|
export default function Playlist() {
|
||||||
|
this._list = [];
|
||||||
|
|
||||||
|
this.songAtIndex = function (index) {
|
||||||
|
return this.list[index];
|
||||||
|
};
|
||||||
|
|
||||||
|
this.songsWithName = function (name) {
|
||||||
|
return this._list.filter((item) => item.getDisplayName() == name);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.add = function (url, name, author) {
|
||||||
|
this._list.push(new PlaylistSong(url, name, author, this, this._list.length));
|
||||||
|
};
|
||||||
|
|
||||||
|
this.remove = function (index) {
|
||||||
|
let removed = this._list.splice(index, 1);
|
||||||
|
if (removed.length > 0) {
|
||||||
|
return removed[0];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.findSongIndex = function (name) {
|
||||||
|
return this._list.findIndex((item) => item.getDisplayName() == name);
|
||||||
|
};
|
||||||
|
}
|
26
src/player/PlaylistSong.js
Normal file
26
src/player/PlaylistSong.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
export default function PlaylistSong(url, name, author, playlist) {
|
||||||
|
this._displayName = name;
|
||||||
|
this._author = author;
|
||||||
|
this._url = url;
|
||||||
|
this._mediaStream = null;
|
||||||
|
this._playlist = playlist;
|
||||||
|
|
||||||
|
this.getAudio = function () {
|
||||||
|
if (this.mediaStream) {
|
||||||
|
return this.mediaStream;
|
||||||
|
}
|
||||||
|
this.mediaStream = new Audio(url);
|
||||||
|
};
|
||||||
|
this.getDisplayName = function () {
|
||||||
|
return this._displayName;
|
||||||
|
};
|
||||||
|
this.getAuthor = function () {
|
||||||
|
return this._getAuthor;
|
||||||
|
};
|
||||||
|
this.getUrl = function () {
|
||||||
|
return this._url;
|
||||||
|
};
|
||||||
|
this.getPlaylist = function () {
|
||||||
|
return this._playlist;
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user