这是我正在做的事情,我读取一个.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
文件以供播放?
File.WriteAllBytes
只会将您的数组中的字节写入磁盘。如果字节数组不构成有效的 mp3 文件,则问题很可能出在其他地方。 - Lorentz Vedeler