Search code examples
c#audiomp3playbackdirectsound

How to play MP3 from Stream using DirectSound


I'm writing a program which at some point downloads an MP3 and stores it into a byte array. Then I create Stream from the bytes.

Not sure how to play the Stream. I don't want to use any dlls except for DirectSound.

Are there any better ways to play the Stream? (not another dll)

If yes, how? And if not, how to play the Stream by DirectSound?


Solution

  • It seems that this is not possible. See the quote from a similar MSDN forum post:

    Raw DirectSound isn't capable of playing mp3-compressed audio. I recommend using DirectShow for this purpose, as it supports a wide variety of formats. You could also use a streaming dsound buffer and do the decompression yourself, but this is probably overkill in your situation.

    Note that I don't recommend using mp3 in your project in any case, since it is not a royalty-free format. Ogg Vorbis is a good alternative.

    Mp3 not royalty free so you will struggle to do it without a 3rd party lib and even so it is not recommended.