如何在WP8中合并MP3文件(编辑)

时间:2014-02-03 16:44:02

标签: c# windows-phone-8 merge mp3

我有MP3文件列表,我想将它们合并到一个文件中。我将文件本地下载到独立存储中,但我不知道如何合并它们。谷歌也没有帮助。我不知道WP8中是否可能。 (2)如果不可能你可以建议什么具体的解决方案(我也在网上有我的文件)。

我在下面编写了用于合并的代码,但这总是写入最后一个文件。

string[] files = new string[] { "001000.mp3", "001001.mp3", "001002.mp3", "001003.mp3", "001004.mp3", "001005.mp3", "001006.mp3", "001007.mp3" };

using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
{
    string newFileName = "001.mp3";
    foreach (string _fileName in files)
    {
        if (storage.FileExists(_fileName))
        {
            byte[] bytes = new byte[1];
            using (var f = new IsolatedStorageFileStream(_fileName, FileMode.Open, storage))
            {
                bytes = new byte[f.Length];
                int byteCount;
                using (var isfs = new IsolatedStorageFileStream(newFileName, FileMode.OpenOrCreate, storage))
                {
                    while ((byteCount = f.Read(bytes, 0, bytes.Length)) > 0)
                    {
                        isfs.Write(bytes, 0, byteCount);
                        isfs.Flush();
                    }
                }
            }
        }
    }
}

如何将文件添加(合并)到新创建的文件的末尾?

1 个答案:

答案 0 :(得分:0)

我在写入文件之前添加了isfs.Seek(0, SeekOrigin.End);。这就是我们如何简单地合并相同的比特率mp3文件。

代码如下所示:

using (var isfs = new IsolatedStorageFileStream(newFileName, FileMode.OpenOrCreate, storage))
{
    isfs.Seek(0, SeekOrigin.End); //THIS LINE DID SOLVE MY PROBLEM
    while ((byteCount = f.Read(bytes, 0, bytes.Length)) > 0)
    {
        isfs.Write(bytes, 0, byteCount);
        isfs.Flush();
    }
}

如果代码似乎更长,请改进我的代码。