Here is a workaround using a self hosted media server
let's start
MainWindow.xaml
<MediaElement x:Name="media" />
MainWindow.cs
public MainWindow()
{
InitializeComponent();
//host a media server on some port
MediaServer ws = new MediaServer(RenderVideo, "http://localhost:8080/");
ws.Run();
//set the media server's url as the source of media element
media.Source = new Uri("http://localhost:8080/");
}
private byte[] RenderVideo(HttpListenerRequest r)
{
//get the video bytes from the server etc. and return the same
return File.ReadAllBytes("e:\\vids\\Wildlife.wmv");
}
MediaServer class
class MediaServer
{
private readonly HttpListener _listener = new HttpListener();
private readonly Func<HttpListenerRequest, byte[]> _responderMethod;
public MediaServer(Func<HttpListenerRequest, byte[]> method, string prefix)
{
if (!HttpListener.IsSupported)
throw new NotSupportedException(
"Needs Windows XP SP2, Server 2003 or later.");
if (prefix == null)
throw new ArgumentException("prefix");
if (method == null)
throw new ArgumentException("method");
_listener.Prefixes.Add(prefix);
_responderMethod = method;
_listener.Start();
}
public void Run()
{
ThreadPool.QueueUserWorkItem((o) =>
{
try
{
while (_listener.IsListening)
{
ThreadPool.QueueUserWorkItem((c) =>
{
var ctx = c as HttpListenerContext;
try
{
byte[] buf = _responderMethod(ctx.Request);
ctx.Response.ContentLength64 = buf.Length;
ctx.Response.ContentType = "application/octet-stream";
ctx.Response.OutputStream.Write(buf, 0, buf.Length);
}
catch { }
finally
{
ctx.Response.OutputStream.Close();
}
}, _listener.GetContext());
}
}
catch { }
});
}
public void Stop()
{
_listener.Stop();
_listener.Close();
}
}
give it a try, I am successful able to play the video, I hope same for you too
For the MediaServer I have used Simple C# Web Server with some modifications.
above could be made shorter using Reactive Extensions. I'll give a try on the same if this works for you.
Also we can make the media server generic to pass the id of the video in url and in return it will stream back the desired video from the DB