Game Development Reference
In-Depth Information
wavFile.Format;
m_DSoundBuffer = new
SecondarySoundBuffer(m_DirectSound,
DSoundBufferDesc);
// Now load the sound.
byte[] wavData = new
byte[DSoundBufferDesc.SizeInBytes];
wavFile.Read(wavData, 0,
(int)wavFile.Length);
m_DSoundBuffer.Write(wavData, 0,
LockFlags.None);
// Play our music and have it loop
continuously.
m_DSoundBuffer.Play(0,
SlimDX.DirectSound.PlayFlags.Looping);
}
}
The first line in this method creates our DirectSound object.
Tip
In a real program, you would have much better error handling than we have in
our demos in this topic. It has been left out to save space.
In this case, we would need to handle the situation where the creation of the Direc-
tSound object fails. This could happen, for example, when the user does not have
a DirectSound-compatible sound card installed in his/her system. If this happens,
SlimDX will throw a DirectSound exception (or error). We would catch the excep-
tion by putting a try block around the initialization code as follows:
Search WWH ::




Custom Search