|
I'm trying to follow a guide in a book. It tells me this line:
wave = new DirectSound.SecondaryBuffer("laser1.wav", sound);
and gives me several more lines. Yet I try this and more wave files and I keep getting the same error.
SoundException was Unhandled
What do I do to make this work, because, I QUOTE from the book, "this is amazingly simple". Thanks in advance.
- I love D-flat!
|
|
|
|
|
You might want to try specifying the fully qualified filespec (this is always a good idea) instead of simply laser1.wav . It's also a good idea to catch possible exceptions, eg:
try {
wave = new DirectSound.SecondaryBuffer("C:\\laser1.wav", sound);
}
catch (SoundException ex) {
}
/ravi
|
|
|
|
|
Could it be a wrong version of DirectSound? Here's the full code.
(one line above...)
private void PlaySound()<br />
{<br />
DirectSound.Device Sound;<br />
DirectSound.SecondaryBuffer Wave;<br />
DirectSound.BufferDescription Description = new DirectSound.BufferDescription();<br />
Description.ControlEffects = true;<br />
<br />
Sound = new DirectSound.Device();<br />
Sound.SetCooperativeLevel(this, CooperativeLevel.Priority);<br />
Wave = new SecondaryBuffer("song1.wav", Description, Sound);<br />
Wave.Play(0, BufferPlayFlags.Default);<br />
}
- I love D-flat!
|
|
|
|
|
MasterSharp wrote: Could it be a wrong version of DirectSound?
What's the message of the exception you caught?
/ravi
|
|
|
|
|
That's also what it gives me in the book. I probably shouldn't deviate too much.
- I love D-flat!
|
|
|
|
|
MasterSharp wrote: That's also what it gives me in the book. I probably shouldn't deviate too much.
Sorry, I don't understand what you're saying. What is "that"?
/ravi
|
|
|
|
|
"laser1.wav" I don't know what to do, and I;m also trying articles on the net too.
- I love D-flat!
|
|
|
|
|
MasterSharp wrote: I don't know what to do,
Well for one you could try what I suggested doing. See my first reply in case you've forgotten.
/ravi
|
|
|
|
|
What does that do? Or how would I do what you're suggesting. I really don't know C#, my friend.
- I love D-flat!
|
|
|
|
|
MasterSharp wrote: What does that do?
Specifiying a fully qualified filespec guarantees that your code will attempt to operate on a file that exists.
MasterSharp wrote: how would I do what you're suggesting.
Edit the code and recompile and re-run your program.
/ravi
|
|
|
|
|
I'm sorry that I'm pushing my help and all, but what would I do in the catch part, to find out? I added the code, except for that.
- I love D-flat!
|
|
|
|
|
I tried it without code in catch, and it doesn't stop the program and give me an error, but I don't hear sound.
- I love D-flat!
|
|
|
|
|
I got the error code from "ex". 2147287038
- I love D-flat!
|
|
|
|
|
MasterSharp wrote: it doesn't stop the program and give me an error
That's probably because you're "eating" the exception (i.e. catching it but not doing anything about the fact that an exception was thrown).
/ravi
|
|
|
|
|
MasterSharp wrote: what would I do in the catch part
The simplest thing to do would be to display a message box if an exception is thrown, eg:
try {
wave = new DirectSound.SecondaryBuffer("C:\\laser1.wav", sound);
}
catch (SoundException ex) {
MessageBox.Show (ex.Message);
}
Also make sure the file C:\\laser1.wav exists.
/ravi
|
|
|
|
|
Ok, so now that we have that done, how could we get the sound to play? I tried severl wave files I see listed in my files, and nothing works. I just want some sounds!
- I love D-flat!
|
|
|
|
|
Was an exception thrown? If so, what's its message?
/ravi
|
|
|
|
|
The error is:
"error in the application - (that big number from a post or 2 ago, Unknown)
string filename, bufferdescription, Device parent
- I love D-flat!
|
|
|
|
|
Sorry, I have no idea what that means. The DirectSound tutorials at this site may help you get on your way. See this[^] section.
/ravi
|
|
|
|
|
Okay; I've gotten the Error t oshow and things. What now? And I really am sorry if I'm pushy.
- I love D-flat!
|
|
|
|
|
MasterSharp wrote: What now?
Hard to say without knowing what the error message is. I'm not psychic.
/ravi
|
|
|
|
|
MasterSharp wrote: I just want some sounds!
You might want to read this[^] article.
MasterSharp wrote: I love D-flat!
May I ask why? Also, did you mean the note or a chord. If so, which one? (I'm a fan of the Em, Am, B7 sequence).
/ravi
|
|
|
|
|
|
Hey. Thanks for the article and trying to help my challenged self. Thanks again!
- I love D-flat!
|
|
|
|
|
MasterSharp wrote: I meant C#.
Ah, that makes sense.
/ravi
|
|
|
|