Initial files for playlist structuring.

This commit is contained in:
Harrison Deng 2022-03-20 19:00:34 -05:00
parent 4dc5e64fa3
commit f33196c013
2 changed files with 54 additions and 0 deletions

28
src/player/Playlist.js Normal file
View 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);
};
}

View 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;
};
}