How to play non-PCM file or convert it to PCM on the fly ?

前端 未结 3 1161
悲哀的现实
悲哀的现实 2021-01-20 01:44

The following code works with some wav files, but with others I get, \"InvalidOperationException was unhandled. Message=Sound API only supports playing PCM wave files.\"

相关标签:
3条回答
  • 2021-01-20 01:49

    The way to do it is to use newkie's code at: http://www.codeproject.com/Articles/175030/PlaySound-A-Better-Way-to-Play-Wav-Files-in-C?msg=4366037#xx4366037xx

    In my case, at least, I had to change all of the lowercase x's to uppercase x's, though, to get it to work.

    0 讨论(0)
  • 2021-01-20 02:01

    So, do you want to PLAY the file or CONVERT it ? What is the primary goal ? Do you play it as a prove you can convert it, or do you convert it because you don't know how to play not-converted file ? http://www.catb.org/esr/faqs/smart-questions.html#goal

    Your question's title claims "convert" but the body claims "Play"

    This answer is about playing files.


    You also may try to use FFDShow codecs directly without DirectX intermediate. http://en.wikipedia.org/wiki/Libavcodec and http://libav.org/ and http://ffmpeg.org/ (they recently had a schism)

    Googling for "FFDShow dotnet", "libav dotnet", "ffmpeg dotnet" shows a bunch of libraries to use it, such as

    • https://github.com/ermau/libav.net
    • Controlling ffdshow from .Net
    • Solid FFmpeg wrapper for C#/.NET

    There is also BASS library. It is targeted as sound playback during gaming, so it probably has less range of formats and not much for re-coding. Still many music players are built on top of it. Some says it is the most simple API to use. So it worth considering. http://www.un4seen.com/


    http://MediaInfo.sf.net is a library (native win32/win64 DLL) allowing to check most multimedia formats content. I don't know if using tis C or C++ APis is easy from C# side.

    0 讨论(0)
  • 2021-01-20 02:09

    Look at audiolab library from mitov. It works great

    0 讨论(0)
提交回复
热议问题