AudioTransportSource behavior at end of file


I’ve been using the AudioTransportSource class and running into behavior that was confusing me a bit. I’m noticing that AudioTransportSource::getCurrentPosition() can return a time that is beyond the end of the file length. If I set the position to be the end of the file and then repeatedly call:


The value returned from getCurrentPosition() will increase each time even though the end of the file has been reached. I know I can set up some guards on my end to keep bad time info from making its way through the application, but I didn´t know if this is expected behavior, or if there is something I’m overlooking. Any info would be greatly appreciated.


Are you on the tip? We were getting glitches at the end of files but Jules fixed this a while ago.

Hi Martin,

Thank you for the quick response. Yes we’re using the tip. I actually wasn’t getting audio glitches, just weird UI bugs because the AudioTransportSource was returning position values past EOF. I read more documentation and found the hasStreamFinished() method which will tell you if you’re at the end of the file. I’ve added some code to make the app handle that case correctly, but I’m still a bit confused by the issue I originally mentioned, and whether or not that is the intended behavior.

Looking at the code, it seems that it’s just because it allows its input source to read the last block of data, even if the input source ends halfway through that block, so yes, it’ll probably be a few samples past the end. Changing that might actually be a little tricky, because landing exactly on the last sample isn’t always easy (e.g. if there’s a resampler involved), but I never thought it’d cause anyone problems.

Hi Jules,

It was actually pretty straightforward to have the application listen for an EOF message and respond accordingly, which is probably what I should have been doing all along anyway. I just wanted to verify that the class was working as designed before I made any changes on my end. Everything is working great now. Thank you for the help.


Which kind of file r u using??

If u r using flac files then it might be a bigger probelm.

I have mention it in another thread and given the fix.