Ashram Kane
Ashram Kane

Reputation: 298

Releasing a media file in Windows Media Player Control

In my C# code, I tried to delete a video file while I was playing it by Windows Media Player Control.

I stopped playing, made its URL null, and even close the Media Player Control.

string delFile = axWindowsMediaPlayer1.Ctlcontrols.currentItem.sourceURL;

axWindowsMediaPlayer1.Ctlcontrols.stop();
axWindowsMediaPlayer1.URL = null;
axWindowsMediaPlayer1.close();

File.Delete(delFile);

However, I have faced 'System.UnauthorizedAccessException' because the file was in use.

Is there any way to release the media file connected to my Windows Media Player Control?

Upvotes: 1

Views: 3286

Answers (1)

AlexIIP
AlexIIP

Reputation: 2481

I had the same issue and was able to release the media file using the suggestion provided by @kennyzk above:

axWindowsMediaPlayer1.currentPlaylist.clear(); 

Upvotes: 3

Related Questions