C# WPF MediaElement throws FileNotFoundException for existing files

Viewed 105

I am in the process of implementing a video feature for an image gallery project.

The images and videos are stored on a local network share. The project utilizes two folder paths - one for current images and one for an archive (incl. images of the current date).

Both file shares mentioned above are used on separate pages within the same window and basically have the same functionalities. The only difference being that the page responsible for the current images utilizes a FileSystemWatcher to check for new files.

When an image is selected, the video can also be played in a separate window; when opening the window with the video player, the Uri of the video file is attached as a parameter.

public VideoWindow(Uri uri)
{
    InitializeComponent();

    Loaded += (s, _) =>
    {
        Video.Source = uri;
        Video.Play();
    };
}

And here is the issue I am having right now...

When I open a video from the page with current image files, it works fine, but if I then want to open another video from the page after waiting a while (~2 Minutes), a FileNotFoundException is thrown in the MediaFailed event of the video player.

System.IO.FileNotFoundException: Cannot find the media file. ---> System.Runtime.InteropServices.COMException (0xC00D1197): Exception from HRESULT: 0xC00D1197

If I then restart the application and select the same image / video again, it works fine. The problem also doesn't appear if I open different videos without being idle for a certain period of time.

The strange thing is that the issue only appears when opening videos from the page with current images, and not the archive (which again, also contains all the current images / videos). All videos work perfectly fine when using the Uri from the archive file share.

I already checked if the source is set to the correct path and also disabled the FileSystemWatcher just in case this could cause the issue, but the videos still fail.

The current workaround is to set the Uri to the video file from the archive file share if a MediaFailed event occurs, but this is just a band-aid solution.


[UPDATE]

I made a test application just using a MediaElement with the Uri to the video and it still failed for the folder including the current images.

Afterwards I checked if the error would still occur, if I put the video file in a separate folder within the directory, since the path to the archived videos is structured differently (incl. sub-directories) - and the error didn't occur again.

I checked, if the error would occur, if I put a video file in the main directory of the archive folder and it did throw the FileNotFoundException after being idle for too long.

So the problem only appears if the Uri to the video file has the following structure: [Local server IP address] [Directory] [Video file] and it seems to work perfectly fine when the path includes a sub-directory like [Local server IP address] [Directory] [Sub-directory] [Video file].

Is the root of the issue the file server setup or is there a weird issue with the MediaElement?

0 Answers
Related