473,409 Members | 1,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

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"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Path="~/script/SilverlightControl.js" />
<asp:ScriptReference Path="~/script/SilverlightMedia.js" />
</Scripts>
</asp:ScriptManager>
<div id="mp1p" />

<script type="text/javascript">
//<![CDATA[
Sys.UI.Silverlight.Control.createObject('mp1p', '\u003cobject
type="application/x-silverlight" id="MediaPlayer1"
style="height:240px;width:320px;">\r\n\t\u003ca
href="http://go2.microsoft.com/fwlink/?LinkID=114576&v=1.0">\u003cimg
src="http://go2.microsoft.com/fwlink/?LinkID=108181" alt="Get Microsoft
Silverlight" style="border-width:0;" />\u003c/a>\r\n\u003c/object>');
Sys.Application.initialize();
Sys.Application.add_init(function()
{
// 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
handler)
//$create(Sys.UI.Silverlight.MediaPlayer, { "mediaSource":
"handler/getmediaobject.ashx", "scaleMode": 1, "source":
"skins/mediaplayer/Professional.xaml" }, null, null, $get("mp1p"));
});
//]]>
</script>
</form>
</body>
</html>

----------------------------------------
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 =
System.Web.Services.WsiProfiles.BasicProfile1_1)]
public class getmediaobject : IHttpHandler
{
#region IHttpHandler Members

public bool IsReusable
{
get { return true; }
}

public void ProcessRequest(HttpContext context)
{
ProcessMediaObject(context,
context.Server.MapPath("~/video/3StrikesChipmunk_56.wmv"));
}

#endregion

private void ProcessMediaObject(HttpContext context, string filePath)
{
FileStream fileStream = null;
try
{
context.Response.Clear();
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
days
cachePolicy.SetCacheability(HttpCacheability.Publi c);
cachePolicy.SetValidUntilExpires(true);

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);
context.Response.Flush();
}
else
{
return;
}
}
}
finally
{
if (fileStream != null)
fileStream.Close();

context.Response.End();
}
}
}
}

The really odd part is that the handler *does* work on my local network - it
only
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
Firefox.

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
yourself.

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.

Thanks!
Roger Martin
Nov 5 '08 #1
0 3552

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: jen_designs | last post by:
How do I create custom controls for an embeded video. I need stop, play, pause, etc. Any thoughts?
4
by: Ronald S. Cook | last post by:
I'm a Visual Studio developer confused by seeing these new products coming out... Expression and Silverlight. Is Expression maybe a successor to FrontPage and is Silverlight maybe something to...
0
by: =?Utf-8?B?Um9nZXIgTWFydGlu?= | last post by:
I have a web site under .NET 2.0 that renders videos using the Silverlight media player. The <asp:MediaPlayercontrol only works on .NET 3.5, but I managed to get things working under .NET 2.0 by...
1
by: Faisal Shafiq | last post by:
I want to upload a file direct to the Silverlight Streaming Service from a Web Client such as silverlight application. As per our product requirement we want to upload a .WMV file directly from...
3
by: AliR \(VC++ MVP\) | last post by:
Hi Everyone, I have written a silverlight application, which talks to a WCF service, which was created within the website after watching this video:...
3
by: =?Utf-8?B?Um9nZXIgTWFydGlu?= | last post by:
Note: My apologies for repeating this post from last week, but my nospam alias and profile account were incorrect. I think I have fixed this, so hopefully this post will trigger MS into a response...
13
by: =?Utf-8?B?Um9nZXIgTWFydGlu?= | last post by:
This is a follow-up to my post "Silverlight video doesn't work when file is streamed from handler in ASP.net" at...
7
Curtis Rutland
by: Curtis Rutland | last post by:
Building A Silverlight (2.0) Multi-File Uploader All source code is C#. VB.NET source is coming soon. Note: This project requires Visual Studio 2008 SP1 or Visual Web Developer 2008 SP1 and...
3
by: pavanip | last post by:
Hi, I am new to Silverlight application.I want to display video using Mediaelement tag and I used the below code to play video. <Canvas> <MediaElement x:Name="mPlayer"...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.