私のセットアップは次のとおりです。
オーディオを録音および再生する Java アプレットをブラウザで実行しています。
私の問題は次のとおりです。
ブラウザーを更新すると、SourceDataLine は更新後に適切に再開されますが、TargetDataLine 自体は再開されません。
public void init() {
try {
DataLine.Info sourceDataLineInfo = new DataLine.Info(
SourceDataLine.class, audioFormat);
DataLine.Info targetDataLineInfo = new DataLine.Info(
TargetDataLine.class, audioFormat);
// Setup a Line.Info instance specifically of the TargetDataLine class.
Line.Info targetDLInfo = new Line.Info(TargetDataLine.class);
Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
Mixer currentMixer = null;
try {
for(int cnt = 0; cnt < mixerInfo.length; cnt++) {
// Get a temporary instance of the current mixer
currentMixer = AudioSystem.getMixer(mixerInfo[cnt]);
if( currentMixer.isLineSupported(targetDLInfo) ) {
Log.log("Found mixer:" + mixerInfo[cnt].getName());
System.out.println(mixerInfo[cnt].getName());
break;
}
//currentMixer = null;
}
} catch(Exception e) {
Log.log("Found no mixer");
}
if(!Client.refresh) {
try {
sourceDataLine = (SourceDataLine) AudioSystem
.getLine(sourceDataLineInfo);
}catch(Exception e){
Log.log("Unable to stream audio not starting playthread");
}
play = new PlayThread();
if(sourceDataLine != null) {
sourceDataLine.open(audioFormat);
sourceDataLine.start();
play.start();
}
try {
targetDataLine = (TargetDataLine) currentMixer.getLine(targetDataLineInfo);
}catch(Exception e) {
connection.addMessage("[WARNING] Your microphone is not working.");
}
capture = new CaptureThread();
if(currentMixer != null) {
if(targetDataLine != null) {
targetDataLine.open(audioFormat);
targetDataLine.start();
capture.start();
}
}else {
connection.addMessage("[WARNING] No compatible microphone found.");
Log.log("Not able to record data since no mixer was found");
}
} else {
sourceDataLine.open(audioFormat);
sourceDataLine.start();
targetDataLine.open(audioFormat);
targetDataLine.start();
}
} catch (Exception e) {
Log.log("An exception occured when trying to startup the audio");
}
}
コードの何が問題になっていますか?