Menu

AudioInputStream not stop

Help
Dan
2013-06-11
2013-06-13
  • Dan

    Dan - 2013-06-11

    Hello!
    I need help!
    I try to write a file from a microphone flats. The file is written, but the program does not stop. I'm trying to stop the recording by line.stop () in another thread. Here's part of my program:

    public void getDataFromLine(TargetDataLine line, File file){
    AudioInputStream ais = new AudioInputStream(line);

        try {
            System.out.println("Audio_start");
            AudioSystem.write(ais, FLACFileWriter.FLAC, file);
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("Audio_stop");
    

    I did a debug on your code and saw that the loop is in the method encodeAudioInputStream of class AudioStreamEncoder. In line:

    while((samplesRead = sin.read(samplesIn, 0, maxRead)!= -1) {
    framesRead = samplesRead/(frameSize);
    .....
    .....

    condition in the loop is never executed. After I do line.stop () is returned array of zeros.
    Maybe I'm doing something wrong? Sorry for my English!

     
  • Preston Lacey

    Preston Lacey - 2013-06-12

    I'm not able to test this at the moment, but try closing the input stream, rather than stopping the line. I'll try to look at it soon if this doesn't help(sorry for the delay).

     
  • Dan

    Dan - 2013-06-12

    Thanks for the help. I've tried to close the inputstream result is the same

     
  • Preston Lacey

    Preston Lacey - 2013-06-12

    My code was expecting it to reach end-of-stream, rather than just return zero samples. Try the latest build(0.3.1). It should work for you now, but let me know if it doesn't. Good luck :)

     
  • Dan

    Dan - 2013-06-13

    Thank you very much. With the new version, everything works perfectly :))

     

Log in to post a comment.