Search code examples
c#audiomp3

How to play a mp3 file from a C# program without adding any dependencies?


In a C# program I'd like to allow users to specify a sound file (wav or mp3) to be played on a certain event.

With a WAV file I can use SoundPlayer, but unfortunately it cannot play anything else (e.g. MP3).

Now I'm looking for a way to play a sound file - wav or mp3 - without adding any dependencies.

Embedding WMP would work, but some people uninstall and it would fail in this case. Additionally I think I'd have to add an additional DLL file - and I really want to keep my application as a single exe file without any additional stuff.


Solution

  • If the main driver is having a single exe file, then you could consider re-packaging dependent files into your executable using a tool like ILMerge (and a much nicer UI for it: NuGenUnify). This would allow you to use a helper library which you can embed in your exe.