diff --git a/src/main/java/musicplayer/Player.java b/src/main/java/musicplayer/Player.java index e4b44b0..5cbd9b8 100644 --- a/src/main/java/musicplayer/Player.java +++ b/src/main/java/musicplayer/Player.java @@ -17,6 +17,10 @@ public class Player { private Song currentSong; private PlayerCallbackInterface callbackInterface; + /** + * Manages GStreamer based playback operations. + * @param callbackInterface Interface on which UI updates can be called. + */ public Player(PlayerCallbackInterface callbackInterface) { this.callbackInterface = callbackInterface; Gst.init(); @@ -36,6 +40,10 @@ public class Player { }); } + /** + * Set a source Song file and start playing it via GStreamer. + * @param song Song to play. + */ public void playSong(Song song) { callbackInterface.setSongHighlighting(song); currentSong = song; @@ -54,6 +62,9 @@ public class Player { callbackInterface.setSeekBarDuration((int) playBin.queryDuration().toSeconds()); } + /** + * Stop any music currently playing. + */ public void stop() { if (this.thread != null) { playBin.stop(); @@ -62,18 +73,30 @@ public class Player { } } + /** + * Resume playing a paused song. + */ public void resume() { playBin.play(); } + /** + * Pause the currently playing song. + */ public void pause() { playBin.pause(); } + /** + * @return The Song currently being played or ready to be played. + */ public Song getCurrentSong(){ return currentSong; } + /** + * @return Current playback position in seconds. + */ public int currentSongPosition(){ return playBin.isPlaying() ? (int) (playBin.getClock().getTime().toSeconds() - playBin.getBaseTime().toSeconds()) : 0; } diff --git a/src/main/java/musicplayer/PlayerGUI.form b/src/main/java/musicplayer/PlayerGUI.form index 3240931..71bbcf9 100644 --- a/src/main/java/musicplayer/PlayerGUI.form +++ b/src/main/java/musicplayer/PlayerGUI.form @@ -1,6 +1,6 @@
- + @@ -8,37 +8,63 @@ - + - + + + - + + + - - + + + + - + + + + + + + + + + + + + + + + + + + + + + + - - + + - + - - - - - - - - - - - + + + + + + + + + - + @@ -67,19 +93,6 @@ - - - - - - - - - - - - - diff --git a/src/main/java/musicplayer/PlayerGUI.java b/src/main/java/musicplayer/PlayerGUI.java index 4700468..1f733dd 100644 --- a/src/main/java/musicplayer/PlayerGUI.java +++ b/src/main/java/musicplayer/PlayerGUI.java @@ -66,10 +66,17 @@ public class PlayerGUI implements PlayerCallbackInterface{ seekBarUpdater.start(); } + /** + * Set the value of seekBar. + * @param position New seekBar value. + */ public void setSeekBarPosition(int position){ SwingUtilities.invokeLater(() -> seekBar.setValue(position)); } + /** + * Reset the libraryView to contain nothing. + */ private void resetTree() { libraryView.removeAll(); DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(); @@ -77,6 +84,10 @@ public class PlayerGUI implements PlayerCallbackInterface{ libraryView.setModel(treeModel); } + /** + * Populate the library with songs grouped by album. + * @param libraryData Map of albums with a lists of associated songs. + */ private void populateLibrary(Map> libraryData) { resetTree(); DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) libraryView.getModel().getRoot(); @@ -87,6 +98,10 @@ public class PlayerGUI implements PlayerCallbackInterface{ }); } + /** + * Populate the library with all songs. + * @param libraryData List of songs. + */ private void populateLibrary(List libraryData) { resetTree(); DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) libraryView.getModel().getRoot(); @@ -94,6 +109,11 @@ public class PlayerGUI implements PlayerCallbackInterface{ } + /** + * Add an item to libraryView. + * @param parentNode Node that should be the parent of this node. + * @param node This node. + */ private void addNodeToTreeModel(DefaultMutableTreeNode parentNode, DefaultMutableTreeNode node) { DefaultTreeModel libraryModel = (DefaultTreeModel) libraryView.getModel(); libraryModel.insertNodeInto(node, parentNode, parentNode.getChildCount()); @@ -102,27 +122,47 @@ public class PlayerGUI implements PlayerCallbackInterface{ } } + /** + * Add a song to the current playlist. + * @param song Song to be added to the playlist. + */ private void addToPlaylist(Song song){ playlistTableModel.addSong(song); playList.revalidate(); } + /** + * Get the next song in the playlist. + * @param currentSong The song that is currently selected. + * @return The next song to be selected. + */ @Override public Song getNextSong(Song currentSong) { return playlistTableModel.nextSong(currentSong); } + /** + * Set the highlighted song in the playlist to this song. + * @param playingSong Song to be highlighted in the playlist. + */ @Override public void setSongHighlighting(Song playingSong) { int index = playlistTableModel.getSongIndex(playingSong); playList.setRowSelectionInterval(index, index); } + /** + * Get the next song in the playlist and dispatch it to the Player to be played. + */ public void playNextSong(){ SwingUtilities.invokeLater(() -> seekBar.setValue(0)); player.playSong(getNextSong(player.getCurrentSong())); } + /** + * Set the maximum value of the seekBar. + * @param seconds New length of seekBar. + */ public void setSeekBarDuration(int seconds){ SwingUtilities.invokeLater(() -> seekBar.setMaximum(seconds)); }