从Mp3读取字节

时间:2013-06-25 20:20:17

标签: c#

我正在使用this库从mp3中读取字节:

List<byte> bytes = new List<byte>();
try
{
    using (WmaStream str = new WmaStream(mp3File, new WaveFormat(RATE, 8, 1)))
    {
        bytes.Capacity = (int)str.Length * 2;
        byte[] buffer = new byte[str.SampleSize * 2];

        int read;
        while ((read = str.Read(buffer, 0, buffer.Length)) > 0)
        {
            for (int i = 0; i < read; i++)
            {
                bytes.Add(buffer[i]);
            }
        }
    }         
}
catch(Exception e)
{

    Console.WriteLine(e.Message);
}
finally
{                
}

return bytes.ToArray();

问题是它有时会引发OutOfMemoryException。我不知道究竟是什么导致了这个问题,但我认为它往往会在阅读大型mp3文件时做到这一点。

知道如何解决这个问题吗?

注意:有趣!当我将平台目标更改为x64而不是x86时,问题就消失了!

0 个答案:

没有答案