Skip to content

Commit f8f1760

Browse files
added getCurrentMixer + test
1 parent c33fc54 commit f8f1760

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,12 @@ public class StreamPlayer implements StreamPlayerInterface, Callable<Void> {
9191
private final Object audioLock = new Object();
9292

9393
// -------------------VARIABLES---------------------
94-
94+
/** Name of the mixer to use */
9595
private String mixerName;
9696

97+
/** The current mixer */
98+
private Mixer mixer = null;
99+
97100
/** The current line buffer size. */
98101
private int currentLineBufferSize = -1;
99102

@@ -520,7 +523,7 @@ private void createLine() throws LineUnavailableException, StreamPlayerException
520523
mixerName = getMixers().get(0);
521524

522525
// Continue
523-
final Mixer mixer = getMixer(mixerName);
526+
mixer = getMixer(mixerName);
524527
if (mixer == null) {
525528
outlet.setSourceDataLine((SourceDataLine) AudioSystem.getLine(lineInfo));
526529
mixerName = null;
@@ -1071,6 +1074,15 @@ public String getMixerName(){
10711074
return mixerName;
10721075
}
10731076

1077+
/**
1078+
* Returns the mixer that is currently being used, if there is no line created this will return null
1079+
*
1080+
* @return The Mixer being used
1081+
*/
1082+
public Mixer getCurrentMixer(){
1083+
return mixer;
1084+
}
1085+
10741086
/**
10751087
* Returns Gain value.
10761088
*

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@
2323
import java.util.Map;
2424
import java.util.logging.Logger;
2525

26-
import javax.sound.sampled.AudioFileFormat;
27-
import javax.sound.sampled.AudioSystem;
28-
import javax.sound.sampled.SourceDataLine;
29-
import javax.sound.sampled.UnsupportedAudioFileException;
26+
import javax.sound.sampled.*;
3027

3128
import org.junit.jupiter.api.BeforeEach;
3229
import org.junit.jupiter.api.Test;
@@ -624,15 +621,29 @@ void setMixer() throws StreamPlayerException {
624621
List<String> mixers = player.getMixers();
625622

626623
//Use the last mixer (this is never the default)
627-
String mixer = mixers.get(mixers.size()-1);
624+
String mixerName = mixers.get(mixers.size()-1);
628625

629626
//Set the mixer
630-
player.setMixerName(mixer);
627+
player.setMixerName(mixerName);
631628

632629
//Create a line, this will either use the set mixer or set the name to null
633630
player.open(audioFile);
634631

635-
assertEquals(mixer, player.getMixerName());
632+
//The name of the mixers should correspond
633+
assertEquals(mixerName, player.getMixerName());
634+
635+
//Get the mixer of the used mixerName
636+
Mixer mixer = null;
637+
final Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo();
638+
for (Mixer.Info mixerInfo : mixerInfos) {
639+
if (mixerInfo.getName().equals(mixerName)) {
640+
mixer = AudioSystem.getMixer(mixerInfo);
641+
break;
642+
}
643+
}
644+
645+
//The mixer that is being used should be the same as the one we found
646+
assertEquals(player.getCurrentMixer(), mixer);
636647
}
637648

638649
}

0 commit comments

Comments
 (0)