Nick
Nick

Reputation: 7525

Getting size of an audio file in ASP.NET

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

Upvotes: 1

Views: 2321

Answers (4)

Kurru
Kurru

Reputation: 14321

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]

Upvotes: 1

John K
John K

Reputation: 28869

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.

Upvotes: 0

SLaks
SLaks

Reputation: 887405

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.

Upvotes: 0

Daniel A. White
Daniel A. White

Reputation: 190935

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

Upvotes: 0

Related Questions