I am somewhat new to audio in Java. What I am trying to do is as I am playing audio, I want to repaint my JComponent
, but the SourceDataLine
blocks all other lines of code including other Threads.
Here is my play()
method
public void play()
{
final AudioFormat af =new AudioFormat(Note.SAMPLE_RATE, 8, 1, true, true);
SourceDataLine line;
try {
line = AudioSystem.getSourceDataLine(af);
line.open(af, Note.SAMPLE_RATE);
line.start();
byte[] arr=data;
for(int position=0;position<arr.length;position++)
{
byte[] out={arr[position]};
line.write(out, 0, 1); //Blocks all user input (Mouse and Keyboard)
this.repaint(); //Need to repaint JComponent here
}
line.drain();
line.close();
} catch (LineUnavailableException e) {
e.printStackTrace();
}
}