【问题标题】:writing a byte[] as a mp3 file将 byte[] 写为 mp3 文件
【发布时间】:2013-12-12 19:33:01
【问题描述】:

这就是我正在做的,我读了一个.mp3 文件,用这种方式将它转换成Base64String

using (fileStream)
                    {

                        fileStreamLength = (int)fileStream.Length + 1;
                        fileInBytes = new byte[fileStreamLength];
                        int currbyte = 0, i = 0;

                        while (currbyte != -1)
                        {
                            currbyte = fileStream.ReadByte();
                            fileInBytes[i++] = (byte)currbyte;
                        }

                    }

                    string fileInString = Convert.ToBase64String(fileInBytes);

现在经过一些工作,我再次拥有相同的Base64String,我将通过byte[] asBytesAgain = Convert.FromBase64String(fileInString);将其转换为字节

现在我的问题是如何将这个byte[] 写成.mp3 文件来播放?

【问题讨论】:

    标签: c# .net mp3


    【解决方案1】:
    File.WriteAllBytes("somefile.mp3", asBytesAgain);
    

    【讨论】:

    • 它会创建一个 mp3 文件,但是当我们在媒体播放器上运行它时会出现错误并且无法播放该文件。
    • @SalmanLone File.WriteAllBytes 只会将数组中的字节写入磁盘。如果 bytearray 不构成有效的 mp3 文件,则问题可能出在其他地方。
    • 我正在使用 ReadAllBytes(file);字节,然后做一些操作将其从单声道转换为立体声,然后调用 WriteAllBytes
    • 正是我需要的!非常感谢您提供了一个写出我的字节的单行解决方案!
    猜你喜欢
    • 1970-01-01
    • 2013-12-09
    • 1970-01-01
    • 1970-01-01
    • 2016-09-29
    • 2012-12-23
    • 1970-01-01
    • 1970-01-01
    • 2011-06-18
    相关资源
    最近更新 更多