Home > Archive (Community help, from old helpdesk) > How to get the mediaPlayer to “let go” of a file?

How to get the mediaPlayer to “let go” of a file?

Avatar image
Aug 23, 2015
Archive Agent wrote
I have a mediaPlayer control I’m working with on a form that just plays back local .AVI files – no problem – however the last file it played remains “held” by the player no matter what I do – stop playback, clear the file list for the control etc… it does not let go which prevents me from deleting/moving the file in question. I can run the player on a separate form/dialog that I can then dispose of which works but is less than ideal – just looking for the “correct” way to release the file handle here.
Thanks.

Jeff Lindborg on January 04, 2014 21:43
Completed
0
Vote
Reply
7 Answers
Aug 23, 2015
Archive Agent agent wrote
Roman Minyaylov

Did you tried to call Clear() method of control?

on January 06, 2014 13:21
Aug 23, 2015
Archive Agent agent wrote
Jeff Lindborg

The MediaPlayer control does not have a "clear" method - there are 6 or so methods that contain the word "clear" for clearing audio effects, video effects, dual screen config etc... yes, I did try calling those but the file is still held. I can either empty the file list and add a new dummy file which causes it to let go or dispose of the object - oddly I actually had to resort to forcing the GC to cleanup when I did that or in some cases it still held the file and I couldn't move it.

on January 06, 2014 18:12
Aug 23, 2015
Archive Agent agent wrote
Roman Minyaylov

.Net, Delphi or ActiveX SDK?

on January 07, 2014 18:41
Aug 23, 2015
Archive Agent agent wrote
Jeff Lindborg

.NET

on January 07, 2014 20:10
Aug 23, 2015
Archive Agent agent wrote
Roman Minyaylov

Difficult to told why that's happen, using Stop method we are fully destroy all DirectShow filters used, so, file must be available.

on January 08, 2014 15:37
Aug 23, 2015
Archive Agent agent wrote
Jeff Lindborg

... and yet its not and it's very easy to reproduce. Just make a WinForm app with a MediaPlayer on it, add a file and start playing it - make a stop button that then calls stop and tries to move the file. It will fail %100 of the time. Here's a chunk of code I just wrote and produces the error no problem - the "breakfast.mg" file is playing at the time - call stop and try to move - no go. You library is clearly not releasing the file...

MediaPlayer1.Stop();
try
{
File.Move("c:\\breakfast.mpg", "c:\\breakfast2.mpg");
}
catch (Exception ex)
{
Console.WriteLine(ex);
}

on January 08, 2014 22:56
Aug 23, 2015
Archive Agent agent wrote
Roman Minyaylov

Must work now.

on February 10, 2014 20:18