Added additional playback controls.
This commit is contained in:
parent
069e75b4cd
commit
35c953f473
@ -51,8 +51,12 @@ public class Player {
|
||||
public void playSong(Optional<Song> inputSong){
|
||||
if (playBin.getState() == State.PLAYING)
|
||||
stop();
|
||||
playBin.setState(State.READY);
|
||||
if(inputSong.isPresent()) {
|
||||
if(playBin.getState() == State.PAUSED && inputSong.get() == currentSong) {
|
||||
resume();
|
||||
return;
|
||||
}
|
||||
playBin.setState(State.READY);
|
||||
currentSong = inputSong.get();
|
||||
callbackInterface.setSongHighlighting(currentSong);
|
||||
File songFile = currentSong.getSongFile();
|
||||
@ -111,7 +115,7 @@ public class Player {
|
||||
* @return Current playback position in seconds.
|
||||
*/
|
||||
public int currentSongPosition(){
|
||||
return playBin.isPlaying() ? (int) (playBin.getClock().getTime().toSeconds() - playBin.getBaseTime().toSeconds()) : 0;
|
||||
return playBin.isPlaying() || playBin.getState() == State.PAUSED ? (int) (playBin.getClock().getTime().toSeconds() - playBin.getBaseTime().toSeconds()) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -156,6 +156,11 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
||||
player.playSong(playlistTableModel.nextSong(player.getCurrentSong()));
|
||||
}
|
||||
|
||||
public void playPreviousSong() {
|
||||
SwingUtilities.invokeLater(() -> seekBar.setValue(0));
|
||||
player.playSong(playlistTableModel.previous(player.getCurrentSong()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maximum value of the seekBar.
|
||||
*
|
||||
@ -285,8 +290,8 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
||||
playList.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
||||
playList.getColumnModel().getColumn(0).setPreferredWidth(10);
|
||||
playList.getColumnModel().getColumn(0).setMaxWidth(10);
|
||||
playList.getColumnModel().getColumn(1).setPreferredWidth(30);
|
||||
playList.getColumnModel().getColumn(1).setMaxWidth(30);
|
||||
playList.getColumnModel().getColumn(1).setPreferredWidth(40);
|
||||
playList.getColumnModel().getColumn(1).setMaxWidth(40);
|
||||
JPopupMenu popupMenu = new JPopupMenu();
|
||||
JMenuItem menuItem = new JMenuItem("Remove");
|
||||
menuItem.addActionListener((e) -> playlistTableModel.removeSong(playList.getSelectedRows()));
|
||||
@ -304,8 +309,7 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
||||
private JToolBar createControlButtons() {
|
||||
JToolBar toolBar = new JToolBar();
|
||||
toolBar.setFloatable(false);
|
||||
JButton playButton = new JButton();
|
||||
playButton.setText("Play");
|
||||
JButton playButton = new JButton("Play");
|
||||
playButton.setMnemonic('P');
|
||||
playButton.setDisplayedMnemonicIndex(0);
|
||||
playButton.addActionListener(e -> {
|
||||
@ -317,14 +321,20 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
||||
}
|
||||
});
|
||||
toolBar.add(playButton);
|
||||
JButton stopButton = new JButton();
|
||||
stopButton.setText("Stop");
|
||||
JButton pauseButton = new JButton("Pause");
|
||||
pauseButton.setMnemonic('E');
|
||||
pauseButton.addActionListener(e -> player.pause());
|
||||
toolBar.add(pauseButton);
|
||||
JButton stopButton = new JButton("Stop");
|
||||
stopButton.setMnemonic('S');
|
||||
stopButton.setDisplayedMnemonicIndex(0);
|
||||
stopButton.addActionListener(e -> player.stop());
|
||||
toolBar.add(stopButton);
|
||||
JButton nextButton = new JButton();
|
||||
nextButton.setText("Next");
|
||||
JButton previousButton = new JButton("Previous");
|
||||
previousButton.setMnemonic('R');
|
||||
previousButton.addActionListener(e -> playPreviousSong());
|
||||
toolBar.add(previousButton);
|
||||
JButton nextButton = new JButton("Next");
|
||||
nextButton.setMnemonic('N');
|
||||
nextButton.setDisplayedMnemonicIndex(0);
|
||||
nextButton.addActionListener(e -> playNextSong());
|
||||
|
@ -23,7 +23,7 @@ public class PlaylistTableModel extends AbstractTableModel {
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return 6;
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -36,7 +36,6 @@ public class PlaylistTableModel extends AbstractTableModel {
|
||||
case 2: o = song.getTitle(); break;
|
||||
case 3: o = song.getArtist(); break;
|
||||
case 4: o = song.getAlbum(); break;
|
||||
case 5: o = song.getDiscNumber(); break;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
@ -55,7 +54,6 @@ public class PlaylistTableModel extends AbstractTableModel {
|
||||
case 2: name = "Title"; break;
|
||||
case 3: name = "Artist"; break;
|
||||
case 4: name = "Album"; break;
|
||||
case 5: name = "DiscNo"; break;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
@ -75,10 +73,10 @@ public class PlaylistTableModel extends AbstractTableModel {
|
||||
return songList.size() > 0 ? Optional.of(songList.get(index)) : Optional.empty();
|
||||
}
|
||||
|
||||
public Song previous(Song song){
|
||||
public Optional<Song> previous(Song song){
|
||||
int index = songList.indexOf(song) - 1;
|
||||
if(index < 0) index = songList.size() - 1;
|
||||
return songList.get(index);
|
||||
return songList.size() > 0 ? Optional.of(songList.get(index)) : Optional.empty();
|
||||
}
|
||||
|
||||
public int getSongIndex(Song song){
|
||||
|
Loading…
Reference in New Issue
Block a user