Jump to content
  • Advertisement
Sign in to follow this  
bigbubba

DirectSound Problem

This topic is 5491 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

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. :)

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
Priority 0. And using SoundException. Same Result. SoundException returns the same error "Error in the Application." Any other ideas?


Share this post


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

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!