Skip to content

Commit e12f0b3

Browse files
openLine() moved to outlet:open()
1 parent ed25d8f commit e12f0b3

File tree

2 files changed

+44
-40
lines changed

2 files changed

+44
-40
lines changed

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

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
package com.goxr3plus.streamplayer.stream;
22

3-
import javax.sound.sampled.BooleanControl;
4-
import javax.sound.sampled.Control;
5-
import javax.sound.sampled.FloatControl;
6-
import javax.sound.sampled.SourceDataLine;
3+
import javax.sound.sampled.*;
4+
import java.util.logging.Logger;
75

86
public class Outlet {
97

8+
private final Logger logger;
109
private FloatControl balanceControl;
1110
private FloatControl gainControl;
1211
private BooleanControl muteControl;
1312
private FloatControl panControl;
1413
private SourceDataLine sourceDataLine;
1514

15+
public Outlet(Logger logger) {
16+
this.logger = logger;
17+
}
18+
1619

1720
public FloatControl getBalanceControl() {
1821
return balanceControl;
@@ -114,4 +117,39 @@ void start() {
114117
getSourceDataLine().start();
115118
}
116119

120+
void open(AudioFormat audioFormat, int currentLineBufferSize) throws LineUnavailableException {
121+
logger.info("Entered OpenLine()!:\n");
122+
123+
if (getSourceDataLine() != null) {
124+
getSourceDataLine().open(audioFormat, currentLineBufferSize);
125+
126+
// opened?
127+
if (getSourceDataLine().isOpen()) {
128+
129+
// Master_Gain Control?
130+
if (getSourceDataLine().isControlSupported(FloatControl.Type.MASTER_GAIN))
131+
setGainControl((FloatControl) getSourceDataLine().getControl(FloatControl.Type.MASTER_GAIN));
132+
else setGainControl(null);
133+
134+
// PanControl?
135+
if (getSourceDataLine().isControlSupported(FloatControl.Type.PAN))
136+
setPanControl((FloatControl) getSourceDataLine().getControl(FloatControl.Type.PAN));
137+
else setPanControl(null);
138+
139+
// Mute?
140+
BooleanControl muteControl1 = getSourceDataLine().isControlSupported(BooleanControl.Type.MUTE)
141+
? (BooleanControl) getSourceDataLine().getControl(BooleanControl.Type.MUTE)
142+
: null;
143+
setMuteControl(muteControl1);
144+
145+
// Speakers Balance?
146+
FloatControl balanceControl = getSourceDataLine().isControlSupported(FloatControl.Type.BALANCE)
147+
? (FloatControl) getSourceDataLine().getControl(FloatControl.Type.BALANCE)
148+
: null;
149+
setBalanceControl(balanceControl);
150+
}
151+
}
152+
logger.info("Exited OpenLine()!:\n");
153+
}
154+
117155
}

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

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public StreamPlayer(Logger logger, ExecutorService streamPlayerExecutorService,
171171
this.streamPlayerExecutorService = streamPlayerExecutorService;
172172
this.eventsExecutorService = eventsExecutorService;
173173
listeners = new ArrayList<>();
174-
outlet = new Outlet();
174+
outlet = new Outlet(logger);
175175
reset();
176176
}
177177

@@ -505,41 +505,7 @@ private void createLine() throws LineUnavailableException, StreamPlayerException
505505
* @param currentLineBufferSize
506506
*/
507507
private void openLine(AudioFormat audioFormat, int currentLineBufferSize) throws LineUnavailableException {
508-
509-
logger.info("Entered OpenLine()!:\n");
510-
511-
if (outlet.getSourceDataLine() != null) {
512-
outlet.getSourceDataLine().open(audioFormat, currentLineBufferSize);
513-
514-
// opened?
515-
if (outlet.getSourceDataLine().isOpen()) {
516-
517-
// Master_Gain Control?
518-
if (outlet.getSourceDataLine().isControlSupported(FloatControl.Type.MASTER_GAIN))
519-
outlet.setGainControl((FloatControl) outlet.getSourceDataLine().getControl(FloatControl.Type.MASTER_GAIN));
520-
else outlet.setGainControl(null);
521-
522-
// PanControl?
523-
if (outlet.getSourceDataLine().isControlSupported(FloatControl.Type.PAN))
524-
outlet.setPanControl((FloatControl) outlet.getSourceDataLine().getControl(FloatControl.Type.PAN));
525-
else outlet.setPanControl(null);
526-
527-
// Mute?
528-
BooleanControl muteControl1 = outlet.getSourceDataLine().isControlSupported(BooleanControl.Type.MUTE)
529-
? (BooleanControl) outlet.getSourceDataLine().getControl(BooleanControl.Type.MUTE)
530-
: null;
531-
outlet.setMuteControl(muteControl1);
532-
533-
// Speakers Balance?
534-
FloatControl balanceControl = outlet.getSourceDataLine().isControlSupported(FloatControl.Type.BALANCE)
535-
? (FloatControl) outlet.getSourceDataLine().getControl(FloatControl.Type.BALANCE)
536-
: null;
537-
outlet.setBalanceControl(balanceControl);
538-
}
539-
540-
}
541-
542-
logger.info("Exited OpenLine()!:\n");
508+
outlet.open(audioFormat, currentLineBufferSize);
543509
}
544510

545511
/**

0 commit comments

Comments
 (0)