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 ファイルでのみ発生し、他のファイルは問題なく読み取られます。必要に応じて、競合するファイルを 1 つ送信できます。

------------------------- NAUDIO CODEPLEX のスレッドを参照するように編集------------------ ---------------

Codeplex でこの問題を参照してください Codeplex NAudioで同じ質問

4

1 に答える 1

0

1 回のヒットでファイル全体を読み取ろうとしないでください。代わりに、一度に約 1 秒分の読み取りを行い、Read が 0 を返すまで続けます。

于 2012-09-19T12:54:39.550 に答える