4

I have a UWP page with a MediaPlayerElement. I use it to play some local files (mp3) using a MediaPlayBackList and everything goes right.

But when I do Frame.GoBack() and later I try to Directory.Delete(URL, true) with these files, an System.IO.IOException is happening (Directory is not empty).

I see on Windows Explorer that some files of the playlist are in use and can´t be delete until app is closed. This only happen when playing has started, before I can delete whole directory with no errors.

I have tried calling:

player.MediaPlayer.Dispose();
playbackList = null;

But nothing changes... What could I do to solve this issue? I would like to dispose MediaPlayer to let files unused. I am targeting Anniversary Update (14393) to be able to use MediaPlayer.

Thank you.

WP8_CT
  • 166
  • 1
  • 2
  • 13
  • 2
    Have you tried `MediaPlayer.Stop();`? – Steven Oct 11 '17 at 08:28
  • I don't see Stop method in new MediaPlayer, only Play and Pause, I don't know why.... I want to stop it. Target version project is 14393 – WP8_CT Oct 11 '17 at 08:36
  • Odd, I think I'm talking about a different kind of Mediaplayer then, since Dispose shouldn't be present either. I searched for a bit and I noticed this link, maybe that will help: https://stackoverflow.com/questions/30515450/how-to-dispose-of-system-windows-media-mediaplayer – Steven Oct 11 '17 at 09:40
  • pls try `player.MediaPlayer = null;` – kennyzx Oct 11 '17 at 13:48
  • 2
    I followed your description to make a code sample and test this question, but I cannot reproduce it. I want to know what the `URL` is. Please provide a value of the URL. Maybe, the issue wasn't in "some files are in use". – Xie Steven Oct 12 '17 at 08:10
  • I tried with player.MediaPlayer = null but the error still happens. The URL is a directory path of this type: string title = "discmusic"; string URL = Path.Combine(ApplicationData.Current.LocalFolder.Path, "Library", "Media", title); – WP8_CT Oct 13 '17 at 07:34
  • 1
    @WP8_CT I would suggest that you could use the `DeleteAsync() ` of [StorageFile class](https://learn.microsoft.com/en-us/uwp/api/windows.storage.storagefile#Methods) instead of using `Directory.Delete()` method. – Xie Steven Oct 17 '17 at 08:25

0 Answers0