So far, I've figured out how to make my program play wav files using the following code:
// "sound" is the name for my DirectSound device
DS.BufferDescription desc = new DS.BufferDescription();
desc.ControlEffects = true;
DS.SecondaryBuffer buffer = new DS.SecondaryBuffer( "laser.wav", desc, sound );
buffer.Play( 0, DS.BufferPlayFlags.Default );
But if I try to use an mp3 file as my file source (ie, "music.mp3"), directX throws an exception saying "argument does not fall within the specified range".
Why How can I get my program to play MP3 files I don't mind using wav files for sound effects, but if I use wavs for background music they're going to be enormous!

How do you play MP3's in DirectSound?
Ben0s
This is your friendly reminder.
EricPaul
i would recommend directx.audiovideoplayback.
Imports Microsoft.DirectX.AudioVideoPlayback
Private dff As Audio
and in formload u just choose a file and set it true
dff = New Audio("D:\Musik\Wir sind Helden\1.mp3", True)
now its already playing.
don't know how many resources this needs. but i think its ok for just one backgroundmusikfile
Mudasir
Well DirectShow is the media api for windows - however it is very poorly supported in managed code http://www.thezbuffer.com/articles/364.aspx - there are some altenatives there too.
Shailesh Saini
Steve Tyson
How about this, then I got the following code off of an internet article...
public class Player
{
private string Pcommand;
private bool isOpen;
[DllImport("winmm.dll")]
private static extern long mciSendString(string strCommand,StringBuilder strReturn,int iReturnLength, IntPtr hwndCallback);
public Player()
{
}
public void Close()
{
Pcommand = "close MediaFile";
mciSendString(Pcommand, null, 0, IntPtr.Zero);
isOpen=false;
}
public void Open(string sFileName)
{
Pcommand = "open \"" + sFileName + "\" type mpegvideo alias MediaFile";
mciSendString(Pcommand, null, 0, IntPtr.Zero);
isOpen = true;
}
public void Play(bool loop)
{
if(isOpen)
{
Pcommand = "play MediaFile";
if (loop)
Pcommand += " REPEAT";
mciSendString(Pcommand, null, 0, IntPtr.Zero);
}
}
}
This code works perfectly in an ordinary Windows Form. But in my DirectX environment, I can't get it to make a sound! I call Play() and I just never get anything. I'm using directSound to play sound effects; could this be screwing it up
Please; I've tried so many different solutions; what's it take to play background music from MP3 files!
mrodriguezc
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.
By the way, this doesn't really belong to "graphics" :)
KCTami
Sorry about the wayward post, man, I'd already posted a graphics question before and didn't think to check which category this post landed in! I'll remember this for future questions.
I've never heard of DirectShow before; what is it used for Is there a good tutorial out there on the web somewhere that explains how to use it (preferrably in C#, but if it's C++ I'll read that too). Also, I've heard that a few DirectX libraries like DirectMusic and DirectPlay are being depricated; is DirectShow one of these or have I just never heard of it before
Oh yeah, and could you explain "royalty free format" Like, do you have to pay someone just for using mp3's in your game, or something
Matt_chrs
Okay, this is very strange... even my SDK in the F1 help menu says I should have access to the AudioVideoPlayback namespace, but I don't appear to have it.
I'm using the december 2005 sdk; I thought this thing's been available since last august ...
AllanP
Ken Schall
http://www.thezbuffer.com/articles/364.aspx :
"The whole DirectShow product was moved into the platform SDK (download) and removed from the DirectX SDK in April 2003."
So unless you have an earlier SDK or the platform SDK it won't be there. I think this is too early for the Web Installer to include it too.