472,328 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Silverlight video doesn't work when file is streamed from ASHX han

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 working with the javascript
rather than the server control.

The web page looks like this:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="video5.aspx.cs"
Inherits="GalleryServerPro.Web.video5" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html id="html" xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Path="~/script/Silverlight.js" />
<asp:ScriptReference Path="~/script/SilverlightControl.js" />
<asp:ScriptReference Path="~/script/SilverlightMedia.js" />
</Scripts>
</asp:ScriptManager>
<asp:PlaceHolder ID="phContent" runat="server" />
</form>
</body>
</html>

The code behind:

using System;
using System.Web.UI;

namespace GalleryServerPro.Web
{
public partial class video5 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
phContent.Controls.Add(new LiteralControl("<div id=\"mp1p\" />"));

// Specify direct path to media file. This works.
string script = "Sys.UI.Silverlight.Control.createObject('mp1p ', '<object
type=\"application/x-silverlight\" data=\"data:application/x-silverlight,\"
id=\"mp1\" style=\"height:400px;width:500px;\"><param name=\"Windowless\"
value=\"True\" /><a
href=\"http://go2.microsoft.com/fwlink/?LinkID=114576&v=1.0\"><img
src=\"http://go2.microsoft.com/fwlink/?LinkID=108181\" alt=\"Get Microsoft
Silverlight\" style=\"border-width:0;\"
/></a></object>');Sys.Application.initialize();Sys.Applica tion.add_init(function()
{ $create(Sys.UI.Silverlight.MediaPlayer,
{\"mediaSource\":\"mediaobjects/3StrikesChipmunk_56.wmv\",\"scaleMode\":1,\"source \":\"skins/mediaplayer/Professional.xaml\"
}, null, null, $get(\"mp1p\")); });";

// Specify path to media file via ASHX handler. This does not work.
string scriptWithHandler =
"Sys.UI.Silverlight.Control.createObject('mp1p ', '<object
type=\"application/x-silverlight\" data=\"data:application/x-silverlight,\"
id=\"mp1\" style=\"height:400px;width:500px;\"><param name=\"Windowless\"
value=\"True\" /><a
href=\"http://go2.microsoft.com/fwlink/?LinkID=114576&v=1.0\"><img
src=\"http://go2.microsoft.com/fwlink/?LinkID=108181\" alt=\"Get Microsoft
Silverlight\" style=\"border-width:0;\"
/></a></object>');Sys.Application.initialize();Sys.Applica tion.add_init(function()
{ $create(Sys.UI.Silverlight.MediaPlayer,
{\"mediaSource\":\"/dev/gs/handler/getmediaobject.ashx?OG/v3eAwpo3M6STSva1cvgMqg4K8r1clwFvPuAJQ4YnG7Jcg/xqOru3otGjczWUCt1jB0uimLyDAnGyeGGKVqtng8JweBY9ZkrD cM3bfDbcP4tGfdq9QHP41oV6k5UBDncTxlr3iZTbyiVeDTAkfp 9Ts7bFAHk+n\",\"scaleMode\":1,\"source\":\"skins/mediaplayer/Professional.xaml\"
}, null, null, $get(\"mp1p\")); });";

ScriptManager.RegisterStartupScript(this, typeof(GspPage),
"startupScript", scriptWithHandler, true);
}
}
}

The AXHX handler (I include only the relevant method as the rest of the code
in the handler deals with security and would distract):

private void ProcessMediaObject()
{
// Send the specified file to the client.
FileStream fileStream = null;
try
{
IMimeType mimeType = MimeType.LoadInstanceByFilePath(this._filename);

this._context.Response.Clear();
this._context.Response.ContentType = mimeType.FullType;
this._context.Response.Buffer = false;

HttpCachePolicy cachePolicy = this._context.Response.Cache;
cachePolicy.SetExpires(System.DateTime.Now.AddSeco nds(2592000)); // 30 days
cachePolicy.SetCacheability(HttpCacheability.Publi c);
cachePolicy.SetValidUntilExpires(true);

int bufferSize =
GalleryServerPro.Web.WebsiteController.GetGalleryS erverProConfigSection().Core.MediaObjectDownloadBu fferSize;
byte[] buffer = new byte[bufferSize];
long byteCount;
fileStream = File.OpenRead(this._filepath);
while ((byteCount = fileStream.Read(buffer, 0, buffer.Length)) 0)
{
if (this._context.Response.IsClientConnected)
{
this._context.Response.OutputStream.Write(buffer, 0, buffer.Length);
this._context.Response.Flush();
}
else
{
return;
}
}
}
catch (Exception ex)
{
GalleryServerPro.ErrorHandler.AppErrorHandler.Reco rdErrorInfo(ex);
}
finally
{
if (fileStream != null)
fileStream.Close();

this._context.Response.End();
}
}

The ContentType of the Response is being set to "video/x-ms-wmv".

As long as I specify the path to the video file directly, everything works.
But when I try to use the handler to send the video to the browser, all I get
is an empty media player - I can see the play/pause/other controls but there
is no video.

The really odd part is that I *can* use the handler on my dev PC - it only
fails when I publish the code to the hosting company (Discount ASP.NET). It
happens on both IIS 6 and IIS 7.

I know you are not in the business of providing support for hosting
companies, so my question is: What could possibly be different on the server
that would cause this to fail? I verified that XAML is a valid MIME type.
Aug 19 '08 #1
0 2219

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...
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...
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...
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...
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...
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> ...
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.