diff --git a/src/main/java/musicplayer/PlayerGUI.java b/src/main/java/musicplayer/PlayerGUI.java index 2a627c9..31e79c6 100644 --- a/src/main/java/musicplayer/PlayerGUI.java +++ b/src/main/java/musicplayer/PlayerGUI.java @@ -66,7 +66,10 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf //Action Listeners playButton.addActionListener(e -> { if (playList.getRowCount() > 0) { - player.playSong(playlistTableModel.getFirst()); + if(playList.getSelectedRowCount() > 0) + player.playSong(playlistTableModel.getSong(playList.getSelectedRow())); + else + player.playSong(playlistTableModel.getFirst()); } }); MouseListener mouseListener = new libraryMouseAdapter(); diff --git a/src/main/java/musicplayer/PlaylistTableModel.java b/src/main/java/musicplayer/PlaylistTableModel.java index b9cfe09..bd699b9 100644 --- a/src/main/java/musicplayer/PlaylistTableModel.java +++ b/src/main/java/musicplayer/PlaylistTableModel.java @@ -99,4 +99,8 @@ public class PlaylistTableModel extends AbstractTableModel { songList.remove(song); fireTableDataChanged(); } + + public Optional getSong(int index){ + return songList.size() > 0 && index >= 0 && index < songList.size() ? Optional.of(songList.get(index)) : Optional.empty(); + } }