R
Roger Martin
This is a follow-up to my post "Silverlight video doesn't work when file is
streamed from handler in ASP.net" at
http://www.microsoft.com/communitie...pnet&mid=e9a38d03-83a8-41fc-8950-5ee60d2a18a5.
I have a web site under .NET 2.0 that renders videos using the Silverlight
media player. When I stream the video file (.wmv) to the browser via a
hard-coded link to the file, all is well. And when I use an HTTP handler to
stream the video to the browser, it also plays. BUT... when I use the handler
the Silverlight player has a problem - I cannot jump to different portions of
the video by dragging the position indicator or clicking a new possition.
When I try, the center of the player turns into rotating circles and inside
it says "0". In other words, it is telling me to wait as it moves to the new
position, but it never does.
Furthermore, once I attempt to go to a new position, the Play button no
longer works and there is nothing I can do to get the video to play short of
reloading the page.
I set up two demonstration pages:
http://www.galleryserverpro.com/dev/webapp2/video2.aspx - This uses the
handler and demonstrates the issue. Notice that - for example - you cannot
move the cursor to the middle of the video and click Play.
http://www.galleryserverpro.com/dev/webapp2/video_nohandler.aspx - This is
identical to the first page, except instead of using the handler it
hard-codes a direct link to the .wmv file. You can jump around to different
sections without any trouble.
Using the first link above, I see the issue in these setups:
Win 2008 Server / FF3
Vista / FF3
Win XP / FF2
Win XP / IE6
Interestingly, the handler *does* work in IE7 (Win 2008 Server and Vista).
Below is the HTTP handler:
using System.IO;
using System.Web;
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.AddSeconds(2592000)); // 30
days
cachePolicy.SetCacheability(HttpCacheability.Public);
cachePolicy.SetValidUntilExpires(true);
const int bufferSize = 32768;
byte[] buffer = new byte[bufferSize];
long byteCount;
fileStream = File.OpenRead(filePath);
context.Response.AddHeader("Content-Length",
fileStream.Length.ToString());
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();
}
}
}
}
Thanks for your help!
Roger Martin
Gallery Server Pro
streamed from handler in ASP.net" at
http://www.microsoft.com/communitie...pnet&mid=e9a38d03-83a8-41fc-8950-5ee60d2a18a5.
I have a web site under .NET 2.0 that renders videos using the Silverlight
media player. When I stream the video file (.wmv) to the browser via a
hard-coded link to the file, all is well. And when I use an HTTP handler to
stream the video to the browser, it also plays. BUT... when I use the handler
the Silverlight player has a problem - I cannot jump to different portions of
the video by dragging the position indicator or clicking a new possition.
When I try, the center of the player turns into rotating circles and inside
it says "0". In other words, it is telling me to wait as it moves to the new
position, but it never does.
Furthermore, once I attempt to go to a new position, the Play button no
longer works and there is nothing I can do to get the video to play short of
reloading the page.
I set up two demonstration pages:
http://www.galleryserverpro.com/dev/webapp2/video2.aspx - This uses the
handler and demonstrates the issue. Notice that - for example - you cannot
move the cursor to the middle of the video and click Play.
http://www.galleryserverpro.com/dev/webapp2/video_nohandler.aspx - This is
identical to the first page, except instead of using the handler it
hard-codes a direct link to the .wmv file. You can jump around to different
sections without any trouble.
Using the first link above, I see the issue in these setups:
Win 2008 Server / FF3
Vista / FF3
Win XP / FF2
Win XP / IE6
Interestingly, the handler *does* work in IE7 (Win 2008 Server and Vista).
Below is the HTTP handler:
using System.IO;
using System.Web;
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.AddSeconds(2592000)); // 30
days
cachePolicy.SetCacheability(HttpCacheability.Public);
cachePolicy.SetValidUntilExpires(true);
const int bufferSize = 32768;
byte[] buffer = new byte[bufferSize];
long byteCount;
fileStream = File.OpenRead(filePath);
context.Response.AddHeader("Content-Length",
fileStream.Length.ToString());
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();
}
}
}
}
Thanks for your help!
Roger Martin
Gallery Server Pro