playing mp3's with directsound

Started by
7 comments, last by AnttiKarhu__ 18 years, 7 months ago
Can I play mp3's with directsound only? I build a wav player using dsound only, and want to make an mp3 player as a 'plugin' for this. Thanks for any help, ProgrammingNerd
Advertisement
Not without doing a lot of work. DSound doesn't have support for any file loading - which is why you ahd to write a loader for .wav files. As you probably found, even this isn't that simple - do you support compressed .wav files for instance?

The .mp3 format is a lot more complex and therefore writing a loader is a lot more tricky. It might be interesting if that kind of thing fascinates you but to me a file loader is very dull. There are free libraries available to do this, or DirectShow has built-in support for .mp3 as well as the windows media player version of mp3s. I wrote a DirectShow wrapper to play music in my game for instance.
Yes, DirectSound do not support directly mp3. You have to find some mp3 loader and decoder source code and insert it into your app. But I suggest to use ogg. It's better and completely free. Source and libraries you can find at

http://www.vorbis.com/download_win_1.0.1.psp
You use DirectShow to play mp3s, not DirectSound. Although it might be possible to play it using Directsound, but I have yet to see code that successfully does it.
i m using directshow for playing mp3 files. it 's easy to use.just try it.i know directx 9 sdk doesnt include directshow.but u can use dx 9 for your graphic codes and dx 8.1 for playing mp3 files.dx supports this.good luck.
My loader came from the dxut source code. How can I play mp3's using directshow?

Thanks alot for your replies,
ProgrammingNerd
Would you like to see my DShow wrapper class? It supports loading both a single .mp3 and also basic tracklist functionality. PM me if you're interested.
It is possible to play an MP3 with DirectSound. I wrote a program to do it a little while ago, using the MAD library to decode the file. It is a lot easier to do it with DirectShow, and you get the benifit of being able to play formats other than MP3, like WMA (not that you would want to ;)). Here's some example code for DirectShow:

CoInitialize(NULL);IGraphBuilder* pGraph;CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC, IID_IGraphBuilder, (void**)&pGraph);pGraph->QueryInterface(IID_IMediaControl, (void**)&pControl);pGraph->RenderFile(L"file.mp3", NULL);pControl->Run();


Keep in mind that Ogg Vorbis is an excellent alternative to MP3 (though you will probably have to interface with DirectSound yourself rather than using DirectShow), given that there are no licensing issues like with MP3 and that the compression quality is better. You should probably download the libogg-1.1.2 and libvorbis-1.1.1 source code from the Xiph.org Vorbis section rather than downloading the Win32 Ogg Vorbis SDK from the link somebody else posted because the SDK contains binaries for an older version of Ogg Vorbis.

[Edited by - trevaaar on August 25, 2005 8:21:37 AM]
You might wan't to use Microsoft.DirectX.AudioVideoPlayback instead. I don't know how to use the classes in C++, but it can't be that hard.

In C# audio playback is easy as this:

Audio audio = new Audio("file.mp3", false);
audio.Play();

This topic is closed to new replies.

Advertisement