This project has moved and is read-only. For the latest updates, please go here.

WaveStream.Length gives erroneous value

Oct 16, 2010 at 2:42 PM
Edited Oct 17, 2010 at 11:00 AM

My code polls the WaveStream.Position property at regular intervals to check if the currently playing track has ended, similarly to the NAudioDemo application. However, when comparing the value to WaveStream.Length, the playback often ends before the track has actually ended, resulting in a premature stop. I've compared the behavior to the demo, and it is the same, leading me to think that there is a flaw in the library. Checking the file duration in WMP shows that NAudio reports the file to be a few seconds shorter than it actually is. The files I'm testing with are MP3, I haven't tried it with WAV or anything else yet.

EDIT: After a bit more testing, I've even had playback that ends too late; the player is just sent zeroes, and the TotalTime is longer than it actually is. This is a major flaw in the library, in my opinion.

EDIT 2: I had a look in the issue tracker, and I believe I have found the issue:

This is the most plausible cause. I have yet to try a WAV file, but this issue fits my problem perfectly.

Oct 17, 2010 at 6:58 PM

mp3 total time property is just guesswork. of course, you don't have to use it to determine when to stop if it is not accurate enough for your needs. I've been trying recently to improve mp3 playback in NAudio. My goal is to pass single MP3 frames to the ACM decoder, and track how many samples they decompress into, allowing a sample-accurate length calculation if necessary. However, it hasn't proved as easy to implement as I hoped.


Oct 17, 2010 at 7:11 PM

Thank you for your response. I guess I'll just keep it like it is for now, and it will be fixed when it will be fixed. Wish I knew more about the MP3 format.