Need to find the length of the audio file in minutes in asp.net

I have an asp.net application in which I upload audio files, converting them to a stream and uploading to a database. But I can not find the length of the audio file in minutes. The problem here is that my asp.net application is present in the cloud. I use asp.net upload file management for download. Please suggest a solution for this.

+5
source share
6 answers

You can watch taglib #

0
source

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

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

0
source

Windows Media Player. Com , wmp.dll .

string Duration = null;
WMPLib.WindowsMediaPlayer w = new WMPLib.WindowsMediaPlayer();
WMPLib.IWMPMedia mediaFile = w.newMedia(Filename);
if (mediaFile != null) {
   Duration = mediaFile.durationString;
}
w.close();
0
0

,

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

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

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

You can use this library to get the duration of an audio file.

0
source

All Articles