Hi,
habe schwierigkeiten meine Lautstärke in meinem Player einzurichten.
Bekomme dabei folgende Fehlermeldung:
Das ganze zu folgendem Code:
Vielleicht kann mir ja jemand helfen das Problem zu lösen. Danke im Voraus!
habe schwierigkeiten meine Lautstärke in meinem Player einzurichten.
Bekomme dabei folgende Fehlermeldung:
Code:
Exception in thread "Thread-3" java.lang.IllegalArgumentException: Unsupported control type: Volume
at com.sun.media.sound.AbstractLine.getControl(Unknown Source)
at Player.startPlaying(Player.java:68)
at Player.run(Player.java:59)
Das ganze zu folgendem Code:
Code:
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.FloatControl;
import javax.sound.sampled.SourceDataLine;
public class Player extends Thread{
static boolean weiter;
private AudioInputStream in = null;
private SourceDataLine line = null;
static Thread player = new Thread();
static FloatControl gainControl;
FloatControl gain;
public Player(AudioInputStream aui){
weiter = true;
try{
in = aui;
}catch (Exception d){
}
AudioFormat format = in.getFormat();
DataLine.Info info = new DataLine.Info(SourceDataLine.class,format);
try {
line = (SourceDataLine)AudioSystem.getLine(info);
line.open(format);
System.out.println("Lautstärke : "+ gainControl);
}catch (Exception e) {
System.exit(-2);
}
}
public void stopPlaying(){
if(player!= null){
player.interrupt();
weiter = false;
line.close();
}
}
public void pause(){
line.stop();
}
public void resumeSound(){
line.start();
}
public void run(){
startPlaying();
}
public void startPlaying(){
System.out.println("Thread start");
while(weiter){
int readBytes =0;
byte[] data = new byte[20000];
line.start();
gain = (FloatControl)line.getControl(FloatControl.Type.VOLUME);
gain.setValue(3f);
do{
try {
readBytes = in.read(data,0,data.length);
}catch (Exception e){
//MainClass.logger.error(e.getMessage());
System.exit(-3);
}
if (readBytes!=-1) line.write(data, 0, readBytes);
} while (readBytes != -1);
}
}
}
Vielleicht kann mir ja jemand helfen das Problem zu lösen. Danke im Voraus!