Skip to content

Commit

Permalink
update to fix logic around next music switch
Browse files Browse the repository at this point in the history
  • Loading branch information
Danil Ko committed Aug 15, 2019
1 parent d3dbb8e commit d4b367c
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public void run() {
if(musicPlayerSetting.getCurrentMusicFile() != null && musicPlayerSetting.getCurrentMusicList() != null && musicPlayerSetting.getCurrentMusicMixer() != null) {
MusicPlayerComponent musicPlayerComponent = new MusicPlayerComponent(musicPlayerRepository);
musicPlayerComponent.play();

musicPlayerRepository.nextMusicFile();
}
else
{
Expand Down Expand Up @@ -109,17 +107,25 @@ void play() {
musicPlayerState.setPlaying(true);
musicPlayerState.setFramePosition(0);

boolean nextMusic = true;

while ((byteRead = audioInputStream.read(byteBuffer)) != -1) {
sourceDataLine.write(byteBuffer, 0, byteRead);
musicPlayerState.setFramePosition( musicPlayerState.getFramePosition() + (byteRead / musicPlayerState.getFrameSize()));
musicPlayerRepository.setMusicPlayerState(musicPlayerState);

if ( musicPlayerRepository.getMusicPlayerSetting().getPlay() == false) {

// As it is sent by stop command, stop at current music, not move to next one
nextMusic = false;
break;
}
}

// Only switch if it is a complete music file play, not due to early stop
if(nextMusic) {
musicPlayerRepository.nextMusicFile();
}

} else {
musicPlayerState.setErrorMessage("cannot find target mixer");
Expand Down

0 comments on commit d4b367c

Please sign in to comment.