Skip to content

Commit ed25d8f

Browse files
openLine() ready for move
1 parent 460f7db commit ed25d8f

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/main/java/com/goxr3plus/streamplayer/stream/StreamPlayer.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -385,11 +385,16 @@ private void initLine() throws LineUnavailableException, StreamPlayerException {
385385

386386
if (outlet.getSourceDataLine() == null)
387387
createLine();
388-
if (!outlet.getSourceDataLine().isOpen())
389-
openLine();
390-
else if (!outlet.getSourceDataLine().getFormat().equals(audioInputStream == null ? null : audioInputStream.getFormat())) {
391-
outlet.getSourceDataLine().close();
392-
openLine();
388+
if (!outlet.getSourceDataLine().isOpen()) {
389+
currentLineBufferSize = lineBufferSize >= 0 ? lineBufferSize : outlet.getSourceDataLine().getBufferSize();
390+
openLine(audioInputStream.getFormat(), currentLineBufferSize);
391+
} else {
392+
AudioFormat format = audioInputStream == null ? null : audioInputStream.getFormat();
393+
if (!outlet.getSourceDataLine().getFormat().equals(format)) { // TODO: Check if bug, does equals work as intended?
394+
outlet.getSourceDataLine().close();
395+
currentLineBufferSize = lineBufferSize >= 0 ? lineBufferSize : outlet.getSourceDataLine().getBufferSize();
396+
openLine(audioInputStream.getFormat(), currentLineBufferSize);
397+
}
393398
}
394399
}
395400

@@ -496,14 +501,14 @@ private void createLine() throws LineUnavailableException, StreamPlayerException
496501
* Open the line.
497502
*
498503
* @throws LineUnavailableException the line unavailable exception
504+
* @param audioFormat
505+
* @param currentLineBufferSize
499506
*/
500-
private void openLine() throws LineUnavailableException {
507+
private void openLine(AudioFormat audioFormat, int currentLineBufferSize) throws LineUnavailableException {
501508

502509
logger.info("Entered OpenLine()!:\n");
503510

504511
if (outlet.getSourceDataLine() != null) {
505-
final AudioFormat audioFormat = audioInputStream.getFormat();
506-
currentLineBufferSize = lineBufferSize >= 0 ? lineBufferSize : outlet.getSourceDataLine().getBufferSize();
507512
outlet.getSourceDataLine().open(audioFormat, currentLineBufferSize);
508513

509514
// opened?

src/test/java/com/goxr3plus/streamplayer/stream/StreamPlayerMethodsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ void seekBytes() throws StreamPlayerException {
344344
}
345345

346346

347-
// The methods tested below aren't used otherwhere in this project, nor in XR3Player
347+
// The methods tested below aren't used elsewhere in this project, nor in XR3Player
348348

349349
@Test
350350
void lineBufferSize() {

0 commit comments

Comments
 (0)