解压缩mp3帧

时间:2013-12-22 08:32:20

标签: c# winforms naudio

我试图通过从MemoryStream解压缩来播放MP3,但由于未知原因,mp3帧始终为空。

private MemoryStream audioStream = new MemoryStream();

public void FillMemoryStream(){
    OpenFileDialog openFile = new OpenFileDialog();
    openFile.ShowDialog();

    FileStream f = new FileStream(openFile.FileName, FileMode.Open);
    f.CopyTo(audioStream);
}

因此,在FillMemoryStream方法中,我打开一个mp3文件,然后将所有字节写入名为MemoryStream的{​​{1}}。

audioStream

我使用了NAudio MP3StreamingDemo中的方法进行了修改,而不是使用private void StreamMp3(object state) { fullyDownloaded = true; var url = (string)state; var buffer = new byte[16384 * 4]; // needs to be big enough to hold a decompressed frame IMp3FrameDecompressor decompressor = null; try { using (audioStream) { var readFullyStream = new ReadFullyStream(audioStream); do { if (IsBufferNearlyFull) { Debug.WriteLine("Buffer getting full, taking a break"); Thread.Sleep(500); } else { Mp3Frame frame; try { frame = Mp3Frame.LoadFromStream(readFullyStream); } catch (EndOfStreamException) { fullyDownloaded = true; // reached the end of the MP3 file / stream break; } if (decompressor == null) { decompressor = CreateFrameDecompressor(frame); bufferedWaveProvider = new BufferedWaveProvider(decompressor.OutputFormat); bufferedWaveProvider.BufferDuration = TimeSpan.FromSeconds(20); } int decompressed = decompressor.DecompressFrame(frame, buffer, 0); bufferedWaveProvider.AddSamples(buffer, 0, decompressed); } } while (playbackState != StreamingPlaybackState.Stopped); decompressor.Dispose(); } } finally { if (decompressor != null) { decompressor.Dispose(); } } } 流而是使用了HttpWebResponse。为什么我的“框架”总是为空?

P.S。我不想使用MemoryStream来打开文件,因为mp3的来源将来自udp连接。

更新:

即使我将Mp3FileReader更改为此

FillMemoryStream

我的画面仍为空。

0 个答案:

没有答案