Thursday 23 June 2011

Ranges header with Silverlight HttpWebRequest

Trying to download a large piece of content, and using the Ranges header to do a pause/resume feature or recover from a network problem during download ?
If you're using Silverlight, and using the HttpWebRequest, you'll find that the Ranges header is not allowed! WTF Silverlight team ?

All is not lost though - more magic settings come to your aid. Before creating the request, add these two magic little lines :

WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);
WebRequest.RegisterPrefix("https://", WebRequestCreator.ClientHttp);

This works in SL4 (think it works in SL3 too)

Sliverlight SMF smooth stream player

Can't get your silverlight player to play smooth stream ? Driving you mad ? Yup me too, and this aint the first smoooth stream player I've written ... but not having access to the code for the previous ones, it was driving me crazy.

I kept getting the dreaded AG_E_NETWORK_ERROR 4001 - very helpful.

Anyway, all is not lost. If you're using the SMF (Silverlight Media framework) player as the base player, check you have the following references :
Microsoft.SilverlightMediaFramework.Plugins.SmoothStreaming.dll
Microsoft.Web.Media.SmoothStreaming.dll

And also, make sure you have this magic setting when setting up the PlaylistItem :

DeliveryMethod = DeliveryMethods.AdaptiveStreaming
MyPlayer.Playlist = new ObservableCollection {
new PlaylistItem
{
DeliveryMethod = DeliveryMethods.AdaptiveStreaming,
MediaSource = new Uri(url)
}
};

Monday 20 June 2011

51 Degrees mobile redirect and Orchard CMS

51 Degrees current version doesn't support Orchard CMS at its current version (1.0.4.1).
This is because part of the "should I redirect this page for the current request?" logic is slightly flawed.

Part of the logic checks that the request context's http handler class type is in the following list (or has a base type of an item in the list):

internal static readonly string[] PAGES = new[]
{
"System.Web.UI.Page",
"System.Web.Mvc.MvcHandler",
"System.Web.Mvc.MvcHttpHandler",
"System.Web.UI.MobileControls.MobilePage",
"System.Web.WebPages.WebPageHttpHandler",
};
Thats not going to work for Orchard, because it's http handler does not inherit from any in the list.

So the fix is to alter the list as so :

internal static readonly string[] PAGES = new[]
{
"System.Web.UI.Page",
"System.Web.Mvc.MvcHandler",
"System.Web.Mvc.MvcHttpHandler",
"System.Web.UI.MobileControls.MobilePage",
"System.Web.WebPages.WebPageHttpHandler",
"Orchard.Mvc.Routes.ShellRoute.HttpAsyncHandler",
"Orchard.Mvc.Routes.ShellRoute+HttpAsyncHandler"
};
The list is in the class FiftyOne.Foundation.Mobile.Redirection.Constants - which is in the file named RedirectionConstants.cs

It's not a great fix - but thats because the code is breaking OCP quite severly, and I don't have time to fix right now.
Hope this post saves someone else several hours of debug !