DirectSound Problem

Started by
5 comments, last by bigbubba 19 years, 7 months ago
I am using C# and DirectSound (needless to say from MDX). I am using VS.NET2002 and framework 1.0. I can't get SecondaryBuffer.Play to work. I will be more than happy to post code. I'm curious if anybody has run into this problem. When I do a SecondaryBuffer.Play it throw an exception. When I catch that and MessageBox it, it says, "Error in the Application." For the record, I'm a total newbie with DirectAnything. And C# for that matter. But this code is generated using sample code off the web. One other thing I should mention is that when I download samples from online that are complete applications, those generate the exact same error. Thanks for any help. :)
Advertisement
How do you fill the secondary buffer? And with what? :)
________________________________pro.gram.mer - an organism that turns caffeine into code
Sorry I would have replied sooner but I thought the forum would send me an email if someone responded. :)

I'm passing it a Stream which is supposedly filled with a wav file.

Ok here's what I do:

---------------------------------------------------------------
Declarations:

private DevicesCollection mSystemDevices=null;
private Device mDevice=null;
private SecondaryBuffer mSecBuff=null;
private StreamReader mStream=null;
private BufferDescription desc=null;
private ArrayList mGuids;

---------------------------------------------------------------

try{
// recreate a new buffer description as well
desc = new BufferDescription();
desc.ControlFrequency = true;
desc.ControlPan = true;
desc.ControlVolume = true;

lblStatus.Text="Loading File....";
this.Refresh();
mStream=new StreamReader(txtFilename.Text);
mSecBuff=new SecondaryBuffer(mStream.BaseStream, desc, mDevice);
lblStatus.Text="Playing File....";
mSecBuff.Play(2, 0);
lblStatus.Text="Playing.";
}
catch(Exception ex){
string mBuffer;
string crlf;
crlf=System.Environment.NewLine;

mBuffer="Error"+crlf;
mBuffer+=ex.Message+crlf;
mBuffer+="Source: "+ex.Source+crlf;
mBuffer+="Inner Exception: "+ex.InnerException+crlf;
mBuffer+="Failed.";
lblStatus.Text=mBuffer;
}

---------------------------------------------------------------

Originally I was just passing a filename and device to the SecondaryBuffer constructor. This is after banging my head against many other walls. I should also mention that txtFilename.Text is pointing to a .wav filename for which I have tried selecting something from c:\windows\media.

Thanks. :)

[Edited by - bigbubba on September 8, 2004 5:50:03 PM]
So no one can venture any guesses as to why this might not be working. I am running the samples in the DX9SDK and all the C# based samples are returning the same error. However, all the C++ samples are working just fine. They have no problem. So I am not sure if MDX is supposed to work with .NET framework 1.0 or something. That's the only guess I can make.

Because the DX installation looks fine and the hardware and software look OK if the C++ 7.0 samples are working fine.

Thanks.

Why do you need to play it with a priority of 2? That is, try changing
mSecBuff.Play(2, 0);
to
mSecBuff.Play(0, 0);
. Does that work? If the buffer is created as a deferred buffer, it is necessary to have this be a 0. You also may want to catch a
SoundException
instead of a generic exception, because it should give you more pertinent information.
-bodisiw
Priority 0. And using SoundException. Same Result. SoundException returns the same error "Error in the Application." Any other ideas?


OK Guys, I uninstalled VS.NET2002 and installed VS.NET2003 that I just got today. And my code still didn't work. Returned the same error. However, the DX9SDK sample worked fine.

So I looked in there and found that I didn't do a SetCooperativeLevel on the Device object that I had created. So I put this in my code and it started working as well.

To sum it up, with VS.NET2003, DX9.0c SDK samples worked fine and after SetCooperativeLevel call my code works fine, too. :)

Thanks for all your help.

This topic is closed to new replies.

Advertisement