0

我有这个代码:

static void Main(string[] args)
{
    try
    {
        Mp3FileReader reader = new Mp3FileReader(@"C:\testAudio.mp3");
        long count = reader.Length;
        if (count <= int.MaxValue)
        {
             byte[] info = new byte[count];
             reader.Read(info, 0, (int)count);
             Console.WriteLine("Succesfull read");
        }
        else
             Console.WriteLine("Could not read");
     }
     catch(Exception ex)
     {
         Console.WriteLine(ex);
     }
}

打印出以下异常消息:

System.ArgumentException: Destination array was not long enough. Check destIndex and length, and the array's lower bounds. 
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable) 
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length) 
at NAudio.Wave.AcmMp3FrameDecompressor.DecompressFrame(Mp3Frame frame, Byte[] dest, Int32 destOffset) in C:\NAudio-Source\NAudio\FileFormats\Mp3\Mp3FrameDecompressor.cs:line 50 
at NAudio.Wave.Mp3FileReader.Read(Byte[] sampleBuffer, Int32 offset, Int32 numBytes) in C:\NAudio-Source\NAudio\Wave\WaveStreams\Mp3FileReader.cs:line 338 
at Tester.Program.Main(String[] args) in C:\Tester\Program.cs:line 30

我已经下载了 NAudio 代码并且一直在调试它,但是我找不到错误的原因,正如您在堆栈跟踪中看到的那样,在NAudio-Source\NAudio\FileFormats\Mp3\Mp3FrameDecompressor.cs :第 50 行

难道我做错了什么?顺便说一句,它只发生在几个 mp3 文件中,其他文件读得很好。如果需要,我可以发送一份有冲突的文件。

-------------------------编辑参考NAUDIO CODEPLEX上的线程----- ---------------

在 Codeplex 上查看此问题Codeplex NAudio上的相同问题

4

1 回答 1

0

不要试图一键读取整个文件。相反,一次阅读大约一秒钟,然后继续阅读,直到 Read 返回 0。

于 2012-09-19T12:54:39.550 回答