MusicHandler: make sure player is closed and cleared once track ends.

multithread-playback
Nekojimi 2 years ago
parent e207b34c0f
commit c1d58da8a4
  1. 56
      src/main/java/moe/nekojimi/chords/MusicHandler.java

@ -95,6 +95,11 @@ public class MusicHandler implements AudioSendHandler, Closeable
currentSong.delete();
currentSong = null;
}
if (player != null)
{
player.close();
player = null;
}
currentSong = queueManager.nextSongNeeded();
if (nowPlayingConsumer != null)
nowPlayingConsumer.accept(currentSong);
@ -179,57 +184,6 @@ public class MusicHandler implements AudioSendHandler, Closeable
return ret;
}
// private void fillBuffer(boolean canSkip)
// {
// // use what we have in our buffer to send audio as PCM
// while (audioBuffer.getCurrentNumberOfBytes() < DESIRED_BUFFER_SIZE)
// if (!readData())
// if (!canSkip || !nextSong())
// break;
// }
//
// private boolean readData()
// {
// if (din == null)
// return false;
// try
// {
// // if (din.available() == 0)
// // return false;
// int bytesToRead = DESIRED_BUFFER_SIZE - audioBuffer.getCurrentNumberOfBytes();
// int space = audioBuffer.getSpace();
// if (din.available() > 0 && din.available() < bytesToRead)
// bytesToRead = din.available();
// if (bytesToRead > space)
// bytesToRead = space;
// if (bytesToRead == 0)
// return false;
// byte[] bytes = new byte[bytesToRead];
// // byte[] bytes = din.readNBytes(bytesToRead);
// int read = din.read(bytes);
//// System.out.println("Wanted: " + byteCount + " Space:" + space + " Available: " + din.available() + " To read: " + bytesToRead + " Read: " + read);
// if (read < 0)
// return false;
//// queue.add(bytes);
//
// audioBuffer.add(bytes, 0, read);
// } catch (IOException ex)
// {
// Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
// return false;
// } catch (ArrayIndexOutOfBoundsException ex)
// {
// if (!arrayErr)
// arrayErr = true;
// else
// {
// Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
// return false;
// }
// }
// return true;
// }
public Song getCurrentSong()
{
return currentSong;

Loading…
Cancel
Save