Reputation: 370
Now I have to code a module that auto-generate a sound file (result.mp3) after each process. I use MediaElement in WPF to make audio and slider buttons.
In each process, I have to overwrite the file result.mp3. However, each time I attend to delete the result.mp3 (has used after listening by mediaElement), the program oftens bring an exception: access denied. Certainly, I also reset new Url to stop the MediaElement whenever I generate new audio file.
mediaElement.Stop();
mediaElement.Source=new Uri("result.mp3");
mediaElement.Start();
How can I fix that error?
Upvotes: 0
Views: 1344
Reputation: 370
Finally, I have solution to fix this error.
You have to close mediaElement in these events: 1. The Stop button. 2. The MediaElement_End event
private void stopButton_Event()
{
fileIsPlaying = false;
playtimer.Stop();
mediaElement.Stop();
mediaElement.Close();
seekSlider.Value = 0;
currentTimeTextBlock.Content = "00:00";
buttonPlay.Content = "Play";
}
I still don't know what causes this error
Upvotes: 1