Player can now auto repeat a single song.
This commit is contained in:
parent
6d33c0a6a2
commit
ab0680b5ee
@ -24,6 +24,7 @@ public class GStreamerPlayer implements IPlayer{
|
||||
private final PlayerCallbackInterface callbackInterface;
|
||||
private int currentVolume = 100;
|
||||
private final IPlaylist playlist;
|
||||
private boolean repeatMode = false; // Repeat the current song?
|
||||
|
||||
/**
|
||||
* Manages GStreamer based playback operations.
|
||||
@ -47,6 +48,9 @@ public class GStreamerPlayer implements IPlayer{
|
||||
Thread callbackThing = new Thread(() -> {
|
||||
try {
|
||||
Thread.sleep(1000); // Song is about to finish, wait so we don't cut it off early.
|
||||
if(repeatMode)
|
||||
playSong(currentSong);
|
||||
else
|
||||
playSong(playlist.getNext(currentSong));
|
||||
} catch (InterruptedException | StartPlayingException e) {
|
||||
e.printStackTrace();
|
||||
@ -81,21 +85,16 @@ public class GStreamerPlayer implements IPlayer{
|
||||
playSong(playlist.getActive());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a source Song file and start playing it via GStreamer.
|
||||
* @param inputSong Song to play.
|
||||
*/
|
||||
public void playSong(Optional<Song> inputSong) throws StartPlayingException {
|
||||
private void playSong(Song inputSong) throws StartPlayingException {
|
||||
if (playBin.getState() == State.PLAYING)
|
||||
stop();
|
||||
if(inputSong.isPresent()) {
|
||||
if(playBin.getState() == State.PAUSED && inputSong.get() == currentSong) {
|
||||
if(playBin.getState() == State.PAUSED && inputSong == currentSong) {
|
||||
resume();
|
||||
return;
|
||||
}
|
||||
resetSeek();
|
||||
playBin.setState(State.READY);
|
||||
currentSong = inputSong.get();
|
||||
currentSong = inputSong;
|
||||
playlist.setPlayingSong(currentSong);
|
||||
File songFile = currentSong.getSongFile();
|
||||
if (!songFile.exists()) {
|
||||
@ -117,9 +116,18 @@ public class GStreamerPlayer implements IPlayer{
|
||||
callbackInterface.setSeekBarDuration((int) playBin.queryDuration().toSeconds());
|
||||
}
|
||||
else{
|
||||
throw new StartPlayingException(inputSong.get());
|
||||
throw new StartPlayingException(inputSong);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a source Song file and start playing it via GStreamer.
|
||||
* @param inputSong Song to play.
|
||||
*/
|
||||
public void playSong(Optional<Song> inputSong) throws StartPlayingException {
|
||||
if(inputSong.isPresent()) {
|
||||
playSong(inputSong.get());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -211,4 +219,8 @@ public class GStreamerPlayer implements IPlayer{
|
||||
public boolean isPlaying(){
|
||||
return playBin.isPlaying();
|
||||
}
|
||||
|
||||
public void setRepeat(boolean repeatMode) { this.repeatMode = repeatMode; }
|
||||
|
||||
public boolean isRepeating(){ return repeatMode; }
|
||||
}
|
||||
|
@ -19,4 +19,6 @@ public interface IPlayer {
|
||||
int getVolume();
|
||||
void seek(int position);
|
||||
boolean isPlaying();
|
||||
void setRepeat(boolean repeatMode);
|
||||
boolean isRepeating();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user