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,417
  • 17
  • 75
  • 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
  • 13,730
  • 17
  • 61
  • 80
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
  • 181,601
  • 45
  • 354
  • 430
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
  • 837,282
  • 173
  • 1,862
  • 1,933
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
  • 27,946
  • 29
  • 138
  • 225