w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Why do I get only hear noise after changing the audio input in java?

I am certain the problem is in the actionPerformed() method:

dataLineInfo = new DataLine.Info( TargetDataLine.class ,
getAudioFormat() ) ;
try {
    targetDataLine = (TargetDataLine) currentMixer.getLine(dataLineInfo) ;
    targetDataLine.open(getAudioFormat());
    targetDataLine.start();
    // TODO: You must read what's in the buffer here

} catch (LineUnavailableException e1) {
    e1.printStackTrace();
}

When the Microphone2 object is first created, this part is invoked:

public void run(){

    while(continueLoop){

        n = targetDataLine.read(tempBuffer, 0, tempBuffer.length);

        updateMeter();

        try {
            Object_Output_Stream.writeObject(tempBuffer);
            Object_Output_Stream.reset();

        } catch (IOException ex) {
            ex.printStackTrace();
            continueLoop = false;
        }
    }
}

As you can see, the buffer is read and the output stream is filled with what was in the buffer. This does not happen when the actionPerformed() is invoked.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.