5

I have asp.net application in which i am uploading audio files by converting them into the stream and upload to the database.But not able to find the length of the audio file into minutes.Here problem is that my asp.net application is present in the cloud.For uploading i am using upload file control of asp.net.Please suggest solution for this.

ninds001
  • 51
  • 1
  • 3
  • 2
    what all audio formats you support? – ajay_whiz Apr 19 '11 at 10:14
  • Here is a link to a similar post on stack over flow http://stackoverflow.com/questions/1214040/how-to-get-the-length-of-a-mp3-in-c-sharp – Wajeeh Dec 30 '11 at 05:23
  • Here is a link to a similar post on stack over flow http://stackoverflow.com/questions/1214040/how-to-get-the-length-of-a-mp3-in-c-sharp – Wajeeh Dec 30 '11 at 05:26
  • Here is a link to a similar post on stack over flow [a link](http://stackoverflow.com/questions/1214040/how-to-get-the-length-of-a-mp3-in-c-sharp/)! – Wajeeh Dec 30 '11 at 05:29
  • Here is a link to a similar post on stack over flow http://stackoverflow.com/questions/1214040/how-to-get-the-length-of-a-mp3-in-c-sharp – Wajeeh Dec 30 '11 at 05:33

6 Answers6

0

You could use the NAudio library as suggested in this answer to a similar SO question.

Community
  • 1
  • 1
Mike Guthrie
  • 4,029
  • 2
  • 25
  • 48
0

We can do it easily by given below code

private string GetDuration(string FileFullPath) 
{ 
string duration = ""; 
string fName = FileFullPath.Substring(FileFullPath.LastIndexOf("\\") + 1); 
string filePath = FileFullPath.Substring(0, FileFullPath.LastIndexOf("\\")); 
Shell32.Shell shell = new Shell32.ShellClass(); 
Shell32.Folder folder = shell.NameSpace(filePath); 
Shell32.FolderItem folderItem = folder.ParseName(fName); 
if (folderItem != null) 
{ 
duration = folder.GetDetailsOf(folderItem, 21); 
} 
folderItem = null; 
folder = null; 
shell = null; 
return duration; 
} 
0

You may look at taglib#

ajay_whiz
  • 17,573
  • 4
  • 36
  • 44
0

TimeSpan span= GetWavFileDuration(filePath + "\" + fileName);
string spanSeconds = span.TotalSeconds.ToString(); string[] spanSecondsArray=spanSeconds.Split('.'); spanSeconds = spanSecondsArray[0].ToString();

public static TimeSpan GetWavFileDuration(string fileName) { WaveFileReader wf = new WaveFileReader(fileName);
return wf.TotalTime; }

You can use this library for getting the Audio file duration

0

I would have expected that you can calculate this from the bit rate and the file length: (file.lenghtInBits / kbsp ) / 60 = minutes.

rather assumes that you can get the bit rate from the file header though.

Stuart
  • 1,123
  • 8
  • 24
0

You will need to reference Windows Media Player. Go to Com Add-ins to add the wmp.dll to your project.

string Duration = null;
WMPLib.WindowsMediaPlayer w = new WMPLib.WindowsMediaPlayer();
WMPLib.IWMPMedia mediaFile = w.newMedia(Filename);
if (mediaFile != null) {
   Duration = mediaFile.durationString;
}
w.close();
Zlatan
  • 698
  • 7
  • 16
  • it will work on your client but always returns a duration of 0 for .avi and .wav files on windows server. – Hossein Mar 02 '12 at 11:57