Jump to content
  • Advertisement
Sign in to follow this  
ProgrammingNerd

playing mp3's with directsound

This topic is 4830 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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();

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!