473,396 Members | 1,702 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,396 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 2338

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...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.