The only way to do this with the SoundPlayer class is to use the
PlaySync[
^] method using a new thread. When the thread completes, the sound is over.
So, in C# pseudo-code, you would have something like this:
public class SoundEffect
{
string _soundFile;
Thread _soundThread;
bool _isStopped = true;
public bool IsFinished { get { return _isStopped; } }
public SoundEffect(string soundFile)
{
_soundFile = soundFile;
}
public void Play()
{
if (!_isStopped)
return;
_soundThread = new Thread(PlayThread);
_soundThread.Start();
}
private void PlayThread()
{
_isStopped = false;
System.Media.SoundPlayer player = new System.Media.SoundPlayer(_soundFile);
player.PlaySync();
_isStopped = true;
}
}
Then you can see if the sound is complete or not.