diff --git a/src/App.js b/src/App.js
index 727758a..3fd7571 100644
--- a/src/App.js
+++ b/src/App.js
@@ -28,14 +28,14 @@ const filepath = new Filepath("C:\\Users\\Paoda\\Downloads");
song = await Song.getMetadata(song);
Song.setAlbumArt(song.metadata);
- mp.load(song);
+ mp.loadSong(song);
// mp.play();
mp.element.onended = async () => {
let song = new Song(list[~~(Math.random() * list.length)]);
song = await Song.getMetadata(song);
Song.setAlbumArt(song.metadata);
- mp.load(song);
+ mp.loadSong(song);
mp.play();
};
})();
diff --git a/src/components/Body.js b/src/components/Body.js
index e0d5893..577e352 100644
--- a/src/components/Body.js
+++ b/src/components/Body.js
@@ -29,12 +29,14 @@ export default class Body extends React.Component {
this.initialize();
}
shouldComponentUpdate(nextProps, state) {
- if (this.state.table.id) return this.state.table.id !== state.table.id;
+ if (this.state.table) return this.state.table.id !== state.table.id;
+ else return false;
// On Feb 13 2019 Had problem wehre this.state.table.id was undefined.
// Unable to replicate issue, but it's a serous one. Probably should fix this yeah?
}
render() {
- console.log("Render TableID: " + this.state.table.id);
+ if (this.state.table) console.log("Render TableID: " + this.state.table.id);
+ else console.warn("No Table Present");
return (
diff --git a/src/components/Body/Table.js b/src/components/Body/Table.js
index e103724..23b5282 100644
--- a/src/components/Body/Table.js
+++ b/src/components/Body/Table.js
@@ -1,7 +1,7 @@
import React from "react";
import Song from "../../melodii/Song";
import MusicPlayer from "../../melodii/MusicPlayer";
-import Misc from "../MiscMethods";
+import Misc, { createID } from "../MiscMethods";
import Emitter from "../../melodii/Events";
import Filepath from "../../melodii/Filepath";
import Settings from 'electron-settings';
@@ -10,8 +10,6 @@ import Settings from 'electron-settings';
var active = document.createElement("tr");
active.classList.toggle("active");
-const usedTableIDs = [];
-
const mp = new MusicPlayer();
var JSXcache;
@@ -152,7 +150,7 @@ export default class Table extends React.Component {
let filepath = e.currentTarget.dataset.filepath;
let song = new Song(filepath);
- mp.load(song);
+ mp.loadSong(song);
mp.play();
song = await Song.getMetadata(song);
@@ -173,7 +171,7 @@ export default class Table extends React.Component {
let filepath = e.currentTarget.dataset.filepath;
let song = new Song(filepath);
- mp.load(song);
+ mp.loadSong(song);
mp.play();
song = await Song.getMetadata(song);
@@ -243,29 +241,6 @@ export async function generate(path, template) {
res(table);
});
}
-
- /**
- * Creates a unique ID that is not UUID compliant.
- * - used to distinguish table objects from one another.
- * @param {Number} length
- * @return {String}
- */
- function createID(length) {
- const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
- let id;
-
- do {
- id = "";
- for (let i = 0; i < length; i++) id += chars[randInt(0, chars.length)];
- } while(usedTableIDs.includes(id));
-
- usedTableIDs.push(id);
- return id;
-
- function randInt(min, max) {
- return ~~(Math.random() * (max - min) + min);
- }
- }
}
/**
diff --git a/src/components/MiscMethods.js b/src/components/MiscMethods.js
index 866505c..0cca7ff 100644
--- a/src/components/MiscMethods.js
+++ b/src/components/MiscMethods.js
@@ -1,5 +1,7 @@
import Song from "../melodii/Song";
+const usedTableIDs = [];
+
/**
* - Every Method in this file must be Static and _probably_ Synchronous
* - The Methods contained in this class must only be methods that don't really fit anywhere else
@@ -322,3 +324,26 @@ export default class MiscMethods {
return [stringA, stringB];
}
}
+
+ /**
+ * Creates a unique ID that is not UUID compliant.
+ * - used to distinguish table objects from one another.
+ * @param {Number} length
+ * @return {String}
+*/
+export function createID(length) {
+ const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+ let id;
+
+ do {
+ id = "";
+ for (let i = 0; i < length; i++) id += chars[randInt(0, chars.length)];
+ } while(usedTableIDs.includes(id));
+
+ usedTableIDs.push(id);
+ return id;
+
+ function randInt(min, max) {
+ return ~~(Math.random() * (max - min) + min);
+ }
+}
\ No newline at end of file
diff --git a/src/melodii/MusicPlayer.js b/src/melodii/MusicPlayer.js
index b377238..f816cc3 100644
--- a/src/melodii/MusicPlayer.js
+++ b/src/melodii/MusicPlayer.js
@@ -1,6 +1,7 @@
import Emitter from "./Events";
import SongArchive from "./SongArchive";
import Song from './Song';
+import Playlist from "./Playlist";
var mp = new Audio();
var archive = new SongArchive();
@@ -9,12 +10,14 @@ export default class MusicPlayer {
constructor() {
this.element = mp;
this.isPaused = false;
+
+ this.playlist = null;
}
/** Pauses Music and sets currentTime to 0. */
stop() {
this.pause();
- this.isPaused = false;
+ this.isPaused = false;
this.element.currentTime = 0.0;
}
@@ -39,10 +42,28 @@ export default class MusicPlayer {
}
}
+
+ /**
+ *
+ * @param {Playlist} playlist
+ */
+ load(playlist) {
+ const song = playlist.next();
+ let path = song.location;
+
+ try {
+ this.element.src = this.getURICompatible(path);
+ this.element.load();
+ console.log("'" + path + "'" + " from " + playlist.title + " was succesfully loaded");
+ } catch(e) {
+ console.error(path + " failed to load " + e.name + " from " + playlist.title);
+ }
+ }
+
/** Loads Song
* @param {Song} song
*/
- load(song) {
+ loadSong(song) {
if (archive.getCurrentSong() !== undefined)
archive.add(archive.getCurrentSong());
let path = song.location;
diff --git a/src/melodii/Playlist.js b/src/melodii/Playlist.js
index f68eeb6..2a70e77 100644
--- a/src/melodii/Playlist.js
+++ b/src/melodii/Playlist.js
@@ -1,5 +1,5 @@
import Filepath from "./Filepath";
-import Misc from "../components/MiscMethods";
+import Misc, { createID } from "../components/MiscMethods";
import Song from "./Song";
export default class Playlist {
@@ -11,6 +11,22 @@ export default class Playlist {
*/
constructor(title, path) {
this.initialize(title, path);
+
+ this.id = createID(25);
+
+ this.songs = [];
+ this.currentSong;
+ this.songIndex = 0;
+
+
+ }
+
+ /**
+ * This method returns the "next" song in the playlist.
+ * @return {Song}
+ */
+ next() {
+ return this.songs[this.songIndex++];
}
/**
@@ -50,4 +66,12 @@ export default class Playlist {
res(content);
});
}
+
+ songs() {
+ return this.songs;
+ }
+
+ currentSong() {
+ return this.currentSong;
+ }
}