I'm trying to make a multi-thead player to play many sound effects (mouse hover, click, animations, etc ...). The player works correctly, but I realize that the RAM was filling up every time the sound is played. So I decided to establish a delegate in audio.BufferingEnded
closing the file, but that did not change anything.
My code.
Task.Run(() => {
try
{
var audio = new MediaPlayer { Volume = DataHandler.SoundVolume };
audio.Open(new Uri(GetFullPath(fileName)));
audio.BufferingEnded += delegate { audio.Close(); };
audio.Play();
}
catch (Exception) { throw; }
}).ContinueWith(async (t) => {
Console.WriteLine("has finished...");
});
The thing is, I need a multi-thead player to play multiple sound effects, but I need to free space in memory after I finish.
Is there any way to release the MediaPlayer when the play is finished?
If someone can help me, it would be great.