I want a page to play music in my WPF app, I have it working at the minute, but there is a problem.
I have a function that when a specific page opens, it starts playing music.
It works fine, but when you click off the page or go on it multiple times, the music starts slowing down and bugging out, and it starts using absurd amounts of RAM.
Voice calls in Discord also sound ass when it starts bugging everything out, but I'm guessing that's due to the RAM problem.
I just need help trying to figure out how to stop and sort of dispose of the music, so it's not even being used in the code anymore, untils it's page is opened again.
3 Replies
$details
When you ask a question, make sure you include as much detail as possible. Such as code, the issue you are facing, what you expect the result to be, what .NET version you are using and what platform/environment (if any) are relevant to your question. Upload code here https://paste.mod.gg/, save, and copy the link into chat for others to see your shared code! (see $code for more information on how to paste your code)
sorry
can do
private void Page_Loaded(object sender, RoutedEventArgs e)
{
BackgroundMusic.Play();
}
private void BackgroundMusic_MediaEnded(object sender, RoutedEventArgs e)
{
BackgroundMusic.Position = TimeSpan.Zero;
BackgroundMusic.Play();
}
I'm using .NET 8.0
After clicking on the page multiple times, RAM usage goes on the app goes to like 2GB and and the audio starts crackling and slowing down.