【问题标题】:Need to find the length of audio file in minutes in asp.net需要在asp.net中以分钟为单位找到音频文件的长度
【发布时间】:2011-04-19 09:27:20
【问题描述】:

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

【问题讨论】:

标签: asp.net


【解决方案1】:

你可以看看taglib#

【讨论】:

    【解决方案2】:

    我希望您可以根据比特率和文件长度来计算:(file.lenghtInBits / kbsp) / 60 = 分钟。

    而是假设您可以从文件头中获取比特率。

    【讨论】:

      【解决方案3】:

      您需要参考 Windows Media Player。转到 Com Add-ins 以将 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();
      

      【讨论】:

      • 它将在您的客户端上运行,但对于 Windows 服务器上的 .avi 和 .wav 文件,它始终返回 0 的持续时间。
      【解决方案4】:

      您可以按照this answer to a similar SO question 中的建议使用NAudio library

      【讨论】:

        【解决方案5】:

        我们可以通过下面的代码轻松做到这一点

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

        【讨论】:

          【解决方案6】:

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

          公共静态时间跨度GetWavFileDuration(字符串文件名){ WaveFileReader wf = new WaveFileReader(fileName);
          返回 wf.TotalTime; }

          You can use this library for getting the Audio file duration

          【讨论】:

          猜你喜欢
          • 2011-06-05
          • 2017-10-05
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-10-23
          • 2015-10-09
          • 2016-06-19
          相关资源
          最近更新 更多