I would prefer something inside of .NET and have troubles believing that
Microsoft would not include sound in the .NET API. In general, I dislike
constantly importing Win32 stuff and then having to copy it everywhere I
need it. Either Microsoft should include all of Win32 in .NET (especially
if they keep calling .NET "better") or they should "preimport" all parts of
Win32 somewhere.
As far as I know, if you want to stay inside .NET, you will have to
use DirectSound from the managed DirectX namespace - I just found this
out last week
You will need to download the huge DirectX SDK at
http://www.microsoft.com/downloads/...20-9DFD-4E7A-B947-3A037CCF84AF&displaylang=en
To use:
Namespaces:
using Microsoft.DirectX;
using Microsoft.DirectX.DirectSound;
using Buffer = Microsoft.DirectX.DirectSound.SecondaryBuffer;
Define variables in your class:
/// <summary>
/// DirectSound: Secondary buffer to hold sound data.
</summary>
private SecondaryBuffer m_dsbSecondaryBuffer = null ;
/// <summary>
/// DirectSound: The Device object is used to create buffer objects,
/// manage devices, and set up the environment.
</summary>
private Device m_dsDevice = null ;
In the constructor:
// Initialize DirectSound device (sound card)
m_dsDevice = new Device( );
m_dsDevice.SetCooperativeLevel( this, CooperativeLevel.Priority );
In your play method:
// Create a DirectSound secondary buffer and fill it with audio data
// from the specified file. The buffer is automatically given the
// correct format and size (?).
try{ m_dsbSecondaryBuffer = new SecondaryBuffer(
strFileName, m_dsDevice ); }
catch( SoundException ){ return ; }
// Play the buffer.
if( null != m_dsbSecondaryBuffer )
m_dsbSecondaryBuffer.Play( 0, BufferPlayFlags.Default );
Hope this helps!
Jan Roelof