Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added setMixerName #65

Merged
merged 4 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions src/main/java/com/goxr3plus/streamplayer/stream/StreamPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,12 @@ public class StreamPlayer implements StreamPlayerInterface, Callable<Void> {
private final Object audioLock = new Object();

// -------------------VARIABLES---------------------

/** Name of the mixer to use */
private String mixerName;

/** The current mixer */
private Mixer mixer = null;

/** The current line buffer size. */
private int currentLineBufferSize = -1;

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

// Continue
final Mixer mixer = getMixer(mixerName);
mixer = getMixer(mixerName);
if (mixer == null) {
outlet.setSourceDataLine((SourceDataLine) AudioSystem.getLine(lineInfo));
mixerName = null;
Expand All @@ -529,8 +532,6 @@ private void createLine() throws LineUnavailableException, StreamPlayerException
outlet.setSourceDataLine((SourceDataLine) mixer.getLine(lineInfo));
}

outlet.setSourceDataLine((SourceDataLine) AudioSystem.getLine(lineInfo));

// --------------------------------------------------------------------------------
logger.info(() -> "Line : " + outlet.getSourceDataLine());
logger.info(() -> "Line Info : " + outlet.getSourceDataLine().getLineInfo());
Expand Down Expand Up @@ -1055,6 +1056,33 @@ private Mixer getMixer(final String name) {
return mixer;
}

/**
* Set the name of the mixer to use. This should be called before opening a Line.
*
* @param mixerName the name
*/
public void setMixerName(String mixerName) {
this.mixerName = mixerName;
}

/**
* Returns the name of the mixer
*
* @return the name of the mixer
*/
public String getMixerName(){
return mixerName;
}

/**
* Returns the mixer that is currently being used, if there is no line created this will return null
*
* @return The Mixer being used
*/
public Mixer getCurrentMixer(){
return mixer;
}

/**
* Returns Gain value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,13 @@ public interface StreamPlayerInterface {
*/
void setLineBufferSize(int size);

/**
* Set the name of the mixer. This should be called before opening a Line.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add this note to the java doc for the implementation function in Stream Player, as most clients calling the function will be calling it from StreamPlayer

*
* @param mixerName the name
*/
void setMixerName(String mixerName);

/**
* Sets Pan value. Line should be opened before calling this method. Linear
* scale : -1.0 ... +1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
import java.util.Map;
import java.util.logging.Logger;

import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.sound.sampled.*;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -618,5 +615,35 @@ void equalizerKey() {
fail("Test not done");
}

@Test
void setMixer() throws StreamPlayerException {
//Get all available mixers
List<String> mixers = player.getMixers();

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

//Set the mixer
player.setMixerName(mixerName);

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

//The name of the mixers should correspond
assertEquals(mixerName, player.getMixerName());

//Get the mixer of the used mixerName
Mixer mixer = null;
final Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo();
for (Mixer.Info mixerInfo : mixerInfos) {
if (mixerInfo.getName().equals(mixerName)) {
mixer = AudioSystem.getMixer(mixerInfo);
break;
}
}

//The mixer that is being used should be the same as the one we found
assertEquals(player.getCurrentMixer(), mixer);
}

}