Introduction

When Silverlight introduced it was considered as a Player Framework because of its capability to handle Rich media. This is one of the first technology to handle true 720p and 1080p HD media. Since its evolution, Silverlight 1 to Silverlight 5 the digital media experience improved a lot. So this post we will take a dig into media concepts and its integration with Silverlight along with various option available.

This post will focus extensively on the Microsoft Media Platform Framework from Microsoft,  a open source player framework and its implementation.

image

Media, Streaming, Silverlight… Journey So far

Silverlight 1 introduced MediaElement object to enable rich media experience. MediaElement is a control region which enables rendering of audio as well video files. It supports Windows Media Video (WMV), Windows Media Audio (WMA), and MP3 files/ Containers.  A detailed list of the formats and protocols supported, can be found with this link Supported Media Formats, Protocols, and Log Fields. Media element object supports Download and Streaming of media content to client side over HTTP. Other than these specified container types the Silverlight provides and option for MediaStreamSource, which enables you to deliver media that doesn’t comes under the supported container type.

Other than format another important aspect of Media rendering is, how the content is going to be delivered at client. This is what called delivery method. There are various method of Delivery of content such as Streaming , Progressive Download Smooth Streaming etc etc. The MediaElement decides on the delivery method based on file format type and the URI.

The Default delivery behaviour of mediaElement is progressive download. If you use the MediaElement with a URL that starts with http: or https:, Silverlight begins a progressive download. If you use the MediaElement with a URL that starts with mms:, Silverlight attempts to stream it, and falls back on a progressive download if streaming fails. Make a note that mediaElement doesn’t support Smooth Streaming.

Before going forward lets have a quick look into various delivery methods and its comparison.

Progressive Download Streaming (Traditional) Smooth Streaming or Adaptive Streaming
Simple HTTP download of files HTTP  based yet stateful (Not exactly HTTP but a modified version of HTTP) Hybrid combination of HTTP streaming with file chunk download
Download a file chunks to client system and user have access to the content downloaded Media sent as a series of packet to client Media  source is divided into many short segments and encoded. Chunks downloaded to client  and played in linear sequence.
Doesn’t consider the client environment Can have multiple versions of file and based client environment can decide which version to send Depending upon CPU and bandwidth usage changes the streaming quality level
User can navigate between the downloaded portion User can seek forward/backward of track Smooth seeking
Longer Initial Time for playback than Streaming Fast Start-up,  No buffering,

If you want to explore in detail on above topics,  have a look into the whitepaper published at Microsoft portal.

In the age of live streaming and on demand video the the smooth Streaming comes to rescue which delivers the best on a given network and client environment. So this leads to Microsoft Media Platform based player which makes it possible at client side to recognize the source content and enable smooth streaming.

Microsoft Media Platform: Player Framework 2.5

Microsoft Media Platform (MMPPF) is open source project from Microsoft that supports media plug-ins such as Smooth Streaming, Progressive Download and Windows Media streaming,.

image

Is this sufficient to use MMPPF? Why at all one should use the framework and what are the benefit it offers? The list bellow shows some of its profound feature in current version 2.5 that worth a shout out -

  • Support for Windows Phone as well as Silverlight
  • Media Plug-ins based on your choice (Smooth Streaming/Progressive Download /WMS)
  • Slow Motion
  • Playline Marker
  • Customization and Branding
  • Logging
  • Advertisement Support
  • Extensibility with Plug-in
  • Streaming Graph Overlay

More detailed description of feature list can be found Here

IIS Smooth Streaming

Make a note that the regular Streaming,  progressive Download are default and come without any extra effort. Smooth streaming requires the files to be stored as chunks of different bit rate so that it can be streamed smoothly to client. Here the client choose which bit rate chunk to be downloaded based on client environment.

But sometime managing so much file chunks can be a difficult task at server so IIS Smooth streaming comes into picture. With IIS Smooth Streaming, file chunks are created virtually upon client request, but the actual video is stored on disk as a single full-length file per encoded bit rate. This offers tremendous file-management benefits.

But for IIS smooth streaming,  IIS server need to be adequately configured and the video file needs to be encoded. There are many server / CDNs are available which offer smooth streaming service, how ever if you want to configure your server to support smooth streaming then refer to this article.

Player download and CodePlex Source

Before jumping to a sample application let me share you the download link and project hosted at CodePlex. It comes as a MSI package which can be installed. Basically it is a set of DLLs which can be referred in the project based on requirement.

Creating a simple Media Player Project

Setting up the Project

Either you can download the binaries or else the complete MSI package which will add MMPPF template to the project window. Once you download the binaries as mentioned above you find a set of assemblies which can be used for based on scenarios. But for a very basic application we need to refer following assemblies into the project

SNAGHTML5a119e

Once you drag and drop the Microsoft.SilverlightMediaFramework.Core.dll to the toolbox,  the SMFPlayer control allows you to use the control directly over page. (As the project was previously called as Silverlight Media Player (SMF) don’t bother about the control name).

image

On use of this control VS will include xmlns:smf=http://schemas.microsoft.com/smf/2010/xaml/player namespace.

<Grid x:Name="LayoutRoot" Background="White">
    <smf:SMFPlayer HorizontalAlignment="Stretch" Margin="0" Name="sMFPlayer" VerticalAlignment="Stretch" />
</Grid> 

Quick Playing Media Source

PlayList and PlayListItem are the basic of MMPPF. PlayListItem indicates the Media source object which is going to be added to Playlist collection of media. Each individual playItem has the option to choose its mode of delivery to the client. Following source shows creation of  a Playlist item from a media source.

//Create a new PlayList Item
PlaylistItem item=new PlaylistItem();
item.MediaSource = new Uri("http://manaspatnaik.com/blog/downloads/Demolishor_WMV_HD.wmv");
item.ThumbSource=new Uri("http://manaspatnaik.com/blog/downloads/demolishor.jpg");
item.DeliveryMethod = Microsoft.SilverlightMediaFramework.Plugins.Primitives.DeliveryMethods.Streaming;
 
//Add PlaylistItem to the Media playlist
sMFPlayer.Playlist.Add(item);
sMFPlayer.Play();

Due to security reason or what so ever it does not support relative source to the playlist instead you can use absolute Uri path for the media item. Same as video Uri it does support Audio playback.

Playing a Smooth Streaming

As I mentioned IIS based smooth streaming needs the server to be configured and for demonstration I am going to use the sample media source hosted over playready.directtaps.net. The smooth streaming media source comes as. ism extension. Well direct use of this extension will not allow you to play the media. Instead you have to use the complete link including "/Manifest". This manifest files define the relationships between the media tracks, bit rates and files at server.

SNAGHTML61cb1d

PlaylistItem item = new PlaylistItem();
item.MediaSource = new Uri("http://playready.directtaps.net/smoothstreaming/SSWSS720H264/SuperSpeedway_720.ism/Manifest");
item.ThumbSource = new Uri(thumbImgUri);
item.DeliveryMethod = Microsoft.SilverlightMediaFramework.Plugins.Primitives.DeliveryMethods.AdaptiveStreaming;
 
//Add PlaylistItem to the Media playlist
sMFPlayer.Playlist.Add(item);

Have a look at the difference between Progressive download and IIS smooth streaming at live link provided at the end of the article.

image

Embedding the Media Player to WordPress or Non Silverlight Site

Embedding the smooth streaming media player needs the XAP file which can be downloaded from here. Include the XAP file with in the   root directory of your hosting provider and in the new wordpress post switch to HTML view where you can use following code.

<object data="data:application/x-silverlight-2," height="100%" type="application/x-silverlight-2" width="100%">
    <param name="source" value="SmoothStreamingPlayer.xap" />
    <param name="minRuntimeVersion" value="4.0.50401.0" />
    <param name="autoUpgrade" value="true" />
    <param name="InitParams" value="mediaurl=http://playready.directtaps.net/smoothstreaming/TTLSS720VC1/To_The_Limit_720.ism/Manifest" />
</object>

As above example is for smooth streaming it support only ism file,  media source that only support IIS 7 smooth streaming. In case you want to host  your own media URL then it needs progressive media player which can be downloaded here.

Sample Embedded player (Smooth Streaming ) – Embedded Player 

Final Words

Media player framework offers lots of feature which I have hardly touched such as Logging, Analytics and Plugin. MMPPF is quite promising and one stop solution for all media rendering  activities. Hope this post will give you a complete picture over Media handling capability that Silverlight does offer. Please feel free to post your views and comments.

Live Link and source code

Additional Links and Reading

推荐.NET配套的通用数据层ORM框架:CYQ.Data 通用数据层框架
新浪微博粉丝精灵,刷粉丝、刷评论、刷转发、企业商家微博营销必备工具"