I am using the sound component to play a sound in a game when a person makes the wrong selection. The button is attached to an eventhandler that plays the error sound file(about 1 second of audio) with player.play(). If the person presses the wrong button quickly it will crash with a few different errors using the following code:
if (player.Playing || player.Paused)
{
await player.Stop();
}
await player.Play(fileName);
Mainly with Object reference not set to an instance of an object.' on the stop command. or with 'Error executing MCI command 'Close All'. Error code: 288. Message: The specified device is now being closed. Wait a few seconds, and then try again.' on the play command.
Is there a better way to do this? Is there any way to reuse the connection and play different sounds without having to destroy the object and restart it every time which seems to be causing the problem here?
I have only tested this on Windows but the application will run on both windows and Linux(Raspberry Pi).