469,601 Members | 2,039 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,601 developers. It's quick & easy.

Silverlight video doesn't work when file is streamed from handler

I have a web site under .NET 2.0 that renders videos using the Silverlight
media player.

The web page looks like this:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="video2.aspx.cs"
Inherits="WebApplication2.video2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<asp:ScriptReference Path="~/script/SilverlightControl.js" />
<asp:ScriptReference Path="~/script/SilverlightMedia.js" />
<div id="mp1p" />

<script type="text/javascript">
Sys.UI.Silverlight.Control.createObject('mp1p', '\u003cobject
type="application/x-silverlight" id="MediaPlayer1"
src="http://go2.microsoft.com/fwlink/?LinkID=108181" alt="Get Microsoft
Silverlight" style="border-width:0;" />\u003c/a>\r\n\u003c/object>');
// This works:
$create(Sys.UI.Silverlight.MediaPlayer, { "mediaSource":
"video/3StrikesChipmunk_56.wmv", "scaleMode": 1, "source":
"skins/mediaplayer/Professional.xaml" }, null, null, $get("mp1p"));

// This does not work (only difference is that it gets the video from the
//$create(Sys.UI.Silverlight.MediaPlayer, { "mediaSource":
"handler/getmediaobject.ashx", "scaleMode": 1, "source":
"skins/mediaplayer/Professional.xaml" }, null, null, $get("mp1p"));

This page works great when I directly reference the video file. But when I
try to use an HTTP handler instead, all I get is an empty Silverlight control
with the Play button disabled and no video. You can repro it by commenting
out the $create line above that references the WMV file and uncomment the
line below it that uses the getmediaobject.ashx handler.

The getmediaobject.ashx handler is straight forward:

using System.IO;
using System.Web;
using System.Web.SessionState;

namespace WebApplication2.handler
[System.Web.Services.WebService(Namespace = "http://tempuri.org/")]
[System.Web.Services.WebServiceBinding(ConformsTo =
public class getmediaobject : IHttpHandler
#region IHttpHandler Members

public bool IsReusable
get { return true; }

public void ProcessRequest(HttpContext context)


private void ProcessMediaObject(HttpContext context, string filePath)
FileStream fileStream = null;
context.Response.ContentType = "video/x-ms-wmv";
context.Response.Buffer = false;

HttpCachePolicy cachePolicy = context.Response.Cache;
cachePolicy.SetExpires(System.DateTime.Now.AddSeco nds(2592000)); // 30
cachePolicy.SetCacheability(HttpCacheability.Publi c);

const int bufferSize = 32768;
byte[] buffer = new byte[bufferSize];
long byteCount;
fileStream = File.OpenRead(filePath);
while ((byteCount = fileStream.Read(buffer, 0, buffer.Length)) 0)
if (context.Response.IsClientConnected)
context.Response.OutputStream.Write(buffer, 0, buffer.Length);
if (fileStream != null)


The really odd part is that the handler *does* work on my local network - it
fails when I publish the code to a web server and then access the page
across the internet. It happens on both IIS 6 and IIS 7, and in IE and

I published the above code at
http://www.galleryserverpro.com/dev/webapp2/video2.aspx. The page is
currently configured to use the handler so that you can see it failing for

Additional info:
1. I am using the final release of 2.0 Silverlight, including the two script
files SilverlightControl.js and SilverlightMedia.js.
2. I have confirmed that no exception is occuring in the handler.
3. Using Firebug I can confirm that the handler is being called and that it
is returning data to the browser.

All evidence points to Silverlight not being able to handle the data
streamed from Silverlight. Perhaps there is a change I can make to the
handler to get it to work, or maybe there is an issue within Silverlight.
Please advise.

Roger Martin
Nov 5 '08 #1
0 3212

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by jen_designs | last post: by
4 posts views Thread by Ronald S. Cook | last post: by
reply views Thread by =?Utf-8?B?Um9nZXIgTWFydGlu?= | last post: by
1 post views Thread by Faisal Shafiq | last post: by
3 posts views Thread by AliR \(VC++ MVP\) | last post: by
3 posts views Thread by =?Utf-8?B?Um9nZXIgTWFydGlu?= | last post: by
13 posts views Thread by =?Utf-8?B?Um9nZXIgTWFydGlu?= | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.