diff --git a/src/player/Playlist.js b/src/player/Playlist.js new file mode 100644 index 0000000..6fa391b --- /dev/null +++ b/src/player/Playlist.js @@ -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); + }; +} \ No newline at end of file diff --git a/src/player/PlaylistSong.js b/src/player/PlaylistSong.js new file mode 100644 index 0000000..9472163 --- /dev/null +++ b/src/player/PlaylistSong.js @@ -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; + }; +} \ No newline at end of file