diff --git a/pom.xml b/pom.xml
index 7012068..b8463d3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,6 +25,11 @@
hsqldb
2.3.3
+
+ com.googlecode.gstreamer-java
+ gstreamer-java
+ 1.5
+
diff --git a/src/main/java/musicplayer/Application.java b/src/main/java/musicplayer/Application.java
index 04bdcca..d924142 100644
--- a/src/main/java/musicplayer/Application.java
+++ b/src/main/java/musicplayer/Application.java
@@ -3,6 +3,7 @@ package musicplayer;
import musicplayer.db.DatabaseManager;
import musicplayer.db.Gateway;
import musicplayer.model.ExtractedMetadata;
+import musicplayer.model.Song;
import org.jaudiotagger.audio.AudioFileIO;
import org.jaudiotagger.audio.exceptions.CannotReadException;
import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException;
@@ -14,19 +15,45 @@ import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.util.List;
import java.util.Optional;
public class Application {
- String musicFileExtensionRegex = ".*\\.(mp3|mp4|flac)";
-
- public static void main(String[] args) {
- new Application();
- }
+ final String musicFileExtensionRegex = ".*\\.(mp3|mp4|flac)";
public Application(){
DatabaseManager.init();
+ List songs = Gateway.listAllSongs().get();
+ boolean running = true;
+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
+ Player player = new Player();
+ while(running){
+ try {
+ System.out.println("Ready to read");
+ String input = br.readLine();
+ System.out.println(input);
+ switch (input) {
+ case "play":
+ player.playSong(songs.get(0).getSongFile());
+ break;
+ case "stop":
+ player.stop();
+ break;
+ case "pause":
+ player.pause();
+ break;
+ case "resume":
+ player.resume();
+ break;
+ case "quit":
+ running = false;
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
}
/**
diff --git a/src/main/java/musicplayer/Player.java b/src/main/java/musicplayer/Player.java
new file mode 100644
index 0000000..cfec8c8
--- /dev/null
+++ b/src/main/java/musicplayer/Player.java
@@ -0,0 +1,61 @@
+package musicplayer;
+
+import org.gstreamer.ElementFactory;
+import org.gstreamer.Gst;
+import org.gstreamer.State;
+import org.gstreamer.elements.PlayBin2;
+
+import java.io.File;
+
+public class Player{
+
+ private PlayBin2 playBin;
+
+ private InternalThread internalThread;
+ private Thread thread;
+
+ public Player(){
+ Gst.init();
+ playBin = new PlayBin2("BusMessages");
+ playBin.setVideoSink(ElementFactory.make("fakesink", "videosink"));
+ }
+
+ public void playSong(File songFile){
+ if(playBin.getState() == State.PLAYING)
+ stop();
+ playBin.setURI(songFile.toURI());
+ internalThread = new InternalThread();
+ thread = new Thread(internalThread);
+ playBin.play();
+ thread.start();
+ }
+
+ public void stop() {
+ if (this.thread != null) {
+ playBin.stop();
+ internalThread.stop();
+ thread.interrupt();
+ thread = null;
+ }
+ }
+
+ public void resume(){
+ playBin.play();
+ }
+
+ public void pause(){
+ playBin.pause();
+ }
+
+ private class InternalThread implements Runnable {
+
+ @Override
+ public void run() {
+ Gst.main();
+ }
+
+ public void stop() {
+ Gst.quit();
+ }
+ }
+}
diff --git a/src/main/java/musicplayer/PlayerGUI.form b/src/main/java/musicplayer/PlayerGUI.form
new file mode 100644
index 0000000..d1ec8f2
--- /dev/null
+++ b/src/main/java/musicplayer/PlayerGUI.form
@@ -0,0 +1,39 @@
+
+
diff --git a/src/main/java/musicplayer/PlayerGUI.java b/src/main/java/musicplayer/PlayerGUI.java
new file mode 100644
index 0000000..7c675de
--- /dev/null
+++ b/src/main/java/musicplayer/PlayerGUI.java
@@ -0,0 +1,69 @@
+package musicplayer;
+
+import musicplayer.db.DatabaseManager;
+import musicplayer.db.Gateway;
+import musicplayer.model.Album;
+import musicplayer.model.Song;
+
+import javax.swing.*;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.DefaultTreeModel;
+import javax.swing.tree.TreeNode;
+import java.util.List;
+import java.util.Map;
+
+public class PlayerGUI {
+ private JTree libraryView;
+ private JList list1;
+ private JPanel mainPanel;
+
+
+ public static void main(String[] args) {
+ JFrame frame = new JFrame();
+ frame.setContentPane(new PlayerGUI().mainPanel);
+ frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+ frame.pack();
+ frame.setVisible(true);
+ }
+
+
+ public PlayerGUI(){
+ DatabaseManager.init();
+ populateLibrary(Gateway.listAllSongsGroupedByAlbum().get());
+ }
+
+ private void resetTree(){
+ libraryView.removeAll();
+ DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
+ DefaultTreeModel treeModel = new DefaultTreeModel(rootNode);
+ libraryView.setModel(treeModel);
+ libraryView.setRootVisible(false);
+ libraryView.setToggleClickCount(1);
+ }
+
+ private void populateLibrary(Map> libraryData){
+ resetTree();
+ DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode)libraryView.getModel().getRoot();
+ libraryData.forEach((k, v) -> {
+ DefaultMutableTreeNode albumNode = new DefaultMutableTreeNode(k);
+ addNodeToTreeModel(parentNode, albumNode);
+ v.forEach(x -> addNodeToTreeModel(albumNode, new DefaultMutableTreeNode(x)));
+ });
+ }
+
+ private void populateLibrary(List libraryData){
+ resetTree();
+ DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode)libraryView.getModel().getRoot();
+ libraryData.forEach(x -> addNodeToTreeModel(parentNode, new DefaultMutableTreeNode(x)));
+
+ }
+
+ private void addNodeToTreeModel(DefaultMutableTreeNode parentNode, DefaultMutableTreeNode node ) {
+ DefaultTreeModel libraryModel = (DefaultTreeModel)libraryView.getModel();
+ libraryModel.insertNodeInto(node, parentNode, parentNode.getChildCount());
+ if (parentNode == libraryModel.getRoot()) {
+ libraryModel.nodeStructureChanged((TreeNode)libraryModel.getRoot());
+ }
+ }
+
+}
diff --git a/src/main/java/musicplayer/model/Album.java b/src/main/java/musicplayer/model/Album.java
index 758936d..e1b676b 100644
--- a/src/main/java/musicplayer/model/Album.java
+++ b/src/main/java/musicplayer/model/Album.java
@@ -19,7 +19,7 @@ public class Album {
}
public String toString(){
- return String.format("ID: %d, Name: %s", id, name);
+ return name;
}
@SuppressWarnings("MethodWithMultipleReturnPoints")
diff --git a/src/main/java/musicplayer/model/Artist.java b/src/main/java/musicplayer/model/Artist.java
index bb4b5c5..c432e4b 100644
--- a/src/main/java/musicplayer/model/Artist.java
+++ b/src/main/java/musicplayer/model/Artist.java
@@ -26,7 +26,7 @@ public class Artist {
}
public String toString(){
- return String.format("ID: %d, Name: %s", id, name);
+ return name;
}
@SuppressWarnings("MethodWithMultipleReturnPoints")
diff --git a/src/main/java/musicplayer/model/Song.java b/src/main/java/musicplayer/model/Song.java
index 431b42f..ee94014 100644
--- a/src/main/java/musicplayer/model/Song.java
+++ b/src/main/java/musicplayer/model/Song.java
@@ -42,7 +42,7 @@ public class Song {
@Override
public String toString(){
- return String.format("Artist: %s, Title: %s, Album: %s, Genre: %s", artist.getName(), title, album.getName(), genre);
+ return title;
}
@SuppressWarnings("MethodWithMultipleReturnPoints")