C# : concatenate 2 MP3 files

后端 未结 6 2164
小鲜肉
小鲜肉 2021-01-05 13:26

I tried to concatenate 2 MP3 files using the code below. I got a new file which I can play the first half of (complete first file), but the second half is silent. The length

6条回答
  •  青春惊慌失措
    2021-01-05 13:50

    As all knows, the Mp3 files are just some frames and you can concatenate the streams together:

    public static void Concatenate(params string[] mp3filenames)
    {
        Stream w = File.OpenWrite("D:\\out.mp3");
    
        foreach (string filename in mp3filenames)
            File.OpenRead(filename).CopyTo(w);    
    
        w.Flush();
        w.Close();
    }
    

    and hears the usage:

    Concatenate("D:\\1.mp3", "D:\\2.mp3");
    

提交回复
热议问题