last day (15 days later) » 

7:49 AM
0
Q: How do I detect the end of AudioInputStream?

TobiqI'm reading audio from a file. I don't know if this is a bug, but the read method is not returning -1 once the end of the file is reached. Even though AudioInputStream#available constantly returns 0 - denoting the end of the file has been reached, AudioInputStream#read(b, off, len) simply retur...

 
@Kayaman for debugging...
From the JavaDoc: Returns the maximum number of bytes that can be read (or skipped over) from this audio input stream without blocking. This limit applies only to the next invocation of a read or skip method for this audio input stream; the limit can vary each time these methods are invoked. Depending on the underlying stream, an IOException may be thrown if this stream is closed.
I don't know if it's designed for debugging, but it's how I used it
There's nothing more to the code, but I'll add anyway
 
All streams return -1 at their end. Now, you never need to call available(), and it's not useful for debugging, so don't bother trying to use it. If you haven't read -1, then you haven't reached the end of the stream. Simple as that.
 
I've clearly reached the end of the stream, because available is constantly returning 0. It's a file, with a finite size.
 
The problem is that while I do understand what available() does, you don't. Which is exactly the reason why you shouldn't be calling the method, because it doesn't do what you think it does. I've got 20+ years of Java experience. I'm telling you to forget about available(), you'll never need it for anything. If your read() returned len, then it means you read the whole buffer.
 
I don't understand why you're so focused on the use of available. It's clearly proved useful here, showing that there's an issue with the implementation of read. The file end has been reached, however, the read function is still returning erroneous values
 
7:49 AM
Because you're not the first one to misunderstand what available() is for, and then think their program does something which it doesn't. I've had this same conversation multiple times. People say "available returns 0 so there's nothing to read". Yeah...no, maybe you should re-read the javadoc.
 
I've used available perfectly here, I already know about how available works, as I've used it before. I.e. with zip streams, where its result is binary.
 
Okay then. You just fix your code then, mr. perfect.
 
@Kayaman You definitely didn't help
 
I tried to. You decided to ignore my knowledge and trust your misconceptions.
 
This question has nothing to do with available... Why do you keep going on about it
 
7:49 AM
Because you're the one using available, and saying that "because available returns 0, it means the file has ended". That's not true of course, but to that you say "I used available perfectly". No, you didn't. And that's the problem. You're the one who brought the whole method in the question, so don't blame me. Blame your own "debugging".
 
@Kayaman read the question.
 
Which version? The latest where you claim there's a bug in read()? I doubt that. Since the bug is most likely in your code, you should show your code.
 
Both version's claimed there was a bug. I added clarification as you wish to be pedantic
 
I thought you might want to add clarification because you want to solve your problem. Or is that not your ultimate goal? You're not showing enough your code, so I can't see where your bug is. All I see is a part of a read-loop.
 
I edited the code
AudioInputStream#available constantly returns 0
 
7:49 AM
You'll have to show more code. The way you construct the audiostream, formats, and so on. Everything. You can't claim there's a bug in the JDK and then not show your code.
 
It's literally the whole test I'm using
 
8:01 AM
Then you should check the frame size, and the bytes you're reading. Is it actually reading (new) data, or does it fill the buffer with the same contents. Or just redirect it to a AudioOutputStream and see if you can play the file instead of just reading it. I haven't touched the audio classes in ages, so I don't remember all the tricks and traps involved, but I do remember there being some
 
 
2 hours later…
9:46 AM
I tried your code with an additional System.out.println(AudioSystem.getAudioFileFormat(inputAudioFile)); in the beginning. It printed AU (.au) file, byte length: 83090, data format: ULAW 8000.0 Hz, 8 bit, mono, 1 bytes/frame, , frame length: 83058 it's a very small audio file. The framesize it 1 bytes. I cut it short killing the program.
I also ran it with no debugging at all.. the program ends all on it's own, but it takes a while.
 
 
2 hours later…
11:52 AM
Do you have a source for a "1MB .wav" where you're experiencing this issue?
 
Zoe
@Scratte OP was chat suspended for over 3200 years in 2018. You won't get answers here any time soon
 
@Zoe Thanks :) I was hoping for an update of the Question though :)
 
Zoe
12:07 PM
They haven't been in chat for 4 hours, so I doubt that
 

last day (15 days later) »