Loading video files programmatically from the network with AxWindowsMediaPlayer

1.4k views Asked by At

OS: Windows 8.1
Apps: Windows Media Player 12
IDE: Visual Studio 2012

I have a C# client application which connects to a server application on another machine. The server app provides the client app with the name of a video file hosted through an http server also running on the remote machine. The client should then load that remote video file and play it. So, unlike all the example tutorials I have found online, the user doesn't get to open a FileDialogBox to pick a file; the filename is provided through code at runtime.

The client application is using Winforms, so I am using the AxWindowsMediaPlayer control to do this. The problem is that it doesn't seem to be able to load the file from the url provided.

For instance, I have this line of code:

this.axWindowsMediaPlayer.URL = "http://192.168.10.100:80/testVideo1.mp4";

When I run that, it gets this error:

'Windows Media Player cannot find the file. If you are trying to play, burn, or sync an item that is in your library, the item might point to a file that has been moved, renamed, or deleted.'

However, if I plug in that same url into a browser window, the file loads right up, and plays the video no problem. Also, if I copy testVideo1.mp4 into the working directory on the local client machine, and try to load the file in code such as this:

this.axWindowsMediaPlayer.URL = "testVideo1.mp4";

Well, that code works, and the video plays. So I know it isn't a codec problem, because the video can be played from the control if the file is local. And I know it isn't a problem with using the wrong url, because it works from the browser.

Is it that Windows Media Player doesn't send an http request, and thus the http server can't process it and forward it to the correct folder? Is there any way to accomplish loading the remote file through AxWindowsMediaPlayer? I would rather not have to download the file to a local folder first.

1

There are 1 answers

2
ThePyroEagle On

Instead of passing it the URL to the website, get your program to download it from the HTTP website and then save it in a temporary local file. Pass the path of that local file to your AxWindowsMediaPlayer.