2011-04-19 70 views
5

我有asp.net应用程序,我通过将音频文件转换成流并上传到数据库来上传音频文件。但无法找到长度为将音频文件分成几分钟。这里的问题是,我的asp.net应用程序存在于云中。对于上传,我正在使用asp.net的上传文件控制。请为此提出解决方案。需要在asp.net中查找音频文件的分钟长度

+2

给你支持什么样的所有音频格式,我们可以很容易地做到这一点? – 2011-04-19 10:14:33

+0

这里是一个链接到一个类似的帖子在堆栈上流 http://stackoverflow.com/questions/1214040/how-to-get-the-length-of-a-mp3-in-c-sharp – Wajeeh 2011-12-30 05:23:08

+0

这里是一个链接到类似的帖子在堆栈上流 http://stackoverflow.com/questions/1214040/how-to-get-the-length-of-a-mp3-in-c-sharp – Wajeeh 2011-12-30 05:26:17

回答

0

我本来期望可以从比特率,文件长度计算如下:(file.lenghtInBits/kbsp)/ 60 =分钟。

宁可假设您可以从文件头获取比特率。

0

您将需要引用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

它将在您的客户端上工作,但对于windows服务器上的.avi和.wav文件,其始终返回持续时间为0。 – desmati 2012-03-02 11:57:17

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; 
}