1

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

Nick
  • 7,475
  • 18
  • 77
  • 128

4 Answers4

1

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
  • 14,180
  • 18
  • 64
  • 84
0

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
  • 187,200
  • 47
  • 362
  • 445
0

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
  • 868,454
  • 176
  • 1,908
  • 1,964
0

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

time length of an mp3 file

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

Community
  • 1
  • 1
John K
  • 28,441
  • 31
  • 139
  • 229