tags:

views:

102

answers:

4

Given an audio file (mp3 or wav), is here a way to get the duration, size (in bytes) and other other attributes of the file?

Thanks

A: 

For the duration, you will need a library. I just found this one on google. http://www.codeplex.com/naudio

As for file size look at the System.IO.File class. http://msdn.microsoft.com/en-us/library/system.io.file.aspx

Daniel A. White
A: 

You can get the file size by writing new FileInfo(path).Length.
If you have it in a stream, you can simply write stream.Length.

To get other information, you'll need audio codecs.

SLaks
A: 

Here's aC++ answer from a similar SO post about how to do it without using a library.

http://stackoverflow.com/questions/119404/time-length-of-an-mp3-file

Although the author wanted Python code, he got something else usable. Maybe the logic is what you need.

John K
+1  A: 

For file size FileInfo would be worth looking at

System.IO.FileInfo file = new System.IO.FileInfo(string filename);
long fileSize = file.Length;

This gets you the file size

and to get attributes like Hidden status. something like the following can get it

  if (file.Attributes & System.IO.FileAttributes.Hidden == System.IO.FileAttributes.Hidden)
  {
       // hidden file
  }

I second the NAudio library for finding the duration of a track [in seconds]

Kurru