c# - NAudio 拆分 mp3 文件

标签 c# asp.net split mp3 naudio

我对音频或 mp3 的东西很陌生,一直在寻找一种方法来具有在 C#、asp.net 中拆分 mp3 文件的功能。在没有太多帮助的情况下用谷歌搜索了 3 天,我希望这里有人能给我指明正确的方向。

我可以使用 NAudio 来完成这个吗?有没有示例代码?提前致谢。

最佳答案

我在 C# 中拆分 mp3 文件的最终解决方案是使用 NAudio。这是一个示例脚本,希望它对社区中的某个人有所帮助:

string strMP3Folder = "<YOUR FOLDER PATH>";
string strMP3SourceFilename = "<YOUR SOURCE MP3 FILENAMe>";
string strMP3OutputFilename = "<YOUR OUTPUT MP3 FILENAME>";

using (Mp3FileReader reader = new Mp3FileReader(strMP3Folder + strMP3SourceFilename))
{
    int count = 1;
    Mp3Frame mp3Frame = reader.ReadNextFrame();
    System.IO.FileStream _fs = new System.IO.FileStream(strMP3Folder + strMP3OutputFilename, System.IO.FileMode.Create, System.IO.FileAccess.Write);

    while (mp3Frame != null)
    {
        if (count > 500) //retrieve a sample of 500 frames
            return;

        _fs.Write(mp3Frame.RawData, 0, mp3Frame.RawData.Length);
        count = count + 1;
        mp3Frame = reader.ReadNextFrame();
     }

     _fs.Close();
}

感谢 Mark Heath 对此的建议。

所需的命名空间是 NAudio.Wave。

关于c# - NAudio 拆分 mp3 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6094287/

相关文章:

c# - 回发时复选框状态重置

c++ - 拆分 malloc 内存空间

java - 如何使用给定的数字和空格来分割字符串?

c# - 有条件地忽略属性序列化

c# - 获取无法访问页面的 Windows 或 IIS 用户

java - 如何打印以空格分隔的同一个字符串n次

c# - 添加相关实体时报错 "Database operation expected to affect 1 row(s) but actually affected 0 row(s)"

c# - 通过 Web api 将大文件(> 1 GB)上传到 Azure Blob 存储

c# - 字节序 java/.net

c# - 反编译 C# 与 C++