最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Using NAudios MediaFoundationEncoder with a Stream throws Exception - Stack Overflow

programmeradmin4浏览0评论

In my C# program, I have a bunch of mp3 files I need to use, but they have different SampleRates, so I want to convert them to a common one. From this example, I created the following code. I want to use a MemoryStream instead of creating a physical file:

ISampleProvider sampleProvider = reader.ToSampleProvider();
var x = new SampleToWaveProvider(sampleProvider);

using (var resampled = new MediaFoundationResampler(x, targetWaveFormat))
{
  Stream stream = new MemoryStream();
  MediaFoundationEncoder.EncodeToMp3(resampled, stream, 0);
  convertedMP3 = new Mp3FileReader(stream);
}

When I use a file instead of the stream it works, but with the stream, new Mp3FileReader(stream) throws the exception "Invalid MP3 file - no MP3 Frames Detected". Both, EncodeToMp3 and Mp3FileReader support "Stream" as parameter.

发布评论

评论列表(0)

  1. 暂无评论