Application of IIS 7 smooth streaming technology in Silverlight 3

Source: Internet
Author: User
Tags introductions reflector microsoft iis

Microsoft's new-generation operating system introduced IIS 7 (Internet Information Services 7) to people's eyes. As an upgraded version of IIS 6.0, IIS 7 has been improved in many places, such as modular service functions, and.. Net seamless integration, simple operations and deployment, improved management functions, security, process improvement, error diagnosis, compatibility, and many other new features, to fully understand more new features brought about by IIS 7, you can refer to the article "exploring web servers for Windows Vista and more content.

Many functions of IIS 7 are integrated into the server as modules (plug-ins). Many common functions have been integrated on IIS 7 installed by default, shows some common modules on IIS 7.

IIS 7 supports many plug-ins. the offical Microsoft IIS Site lists all extensions on current IIS 7, such as search engine optimization toolkit and search engine optimization ), web platform Installer (such as installed under the management category), application request routing, URL rewrite module (I disabled URL rewriter for URL rewriting in "and" ASP. net URL two-way rewrite implementation "describes in detail how to write in a non-IIS 7 environment through ASP. net implements URL rewriting. Now IIS 7 has integrated this function), smooth streaming (this function will be introduced soon), and so on. These plug-ins of IIS 7 bring convenience to site developers, and we may needProgramAdd a lot of complexCodeCurrently, with the help of IIS 7 and plug-ins, you can do this without having to modify any code. Is it exciting? Don't worry. It may take some time to understand or master these plug-ins of IIS 7. the offical Microsoft IIS Site official website has many detailed introductions and examples, for us to learn and study.

In this article, I would like to focus on the application of smooth streaming technology.


What is smooth streaming?

There are detailed introductions and examples on the official site. I believe many people have already seen them. Do you still remember the vivid animated short film big buck bunny? The interesting film shows the application of smooth streaming technology in Silverlight 3. So what is smooth streaming technology? A good explanation is that smooth streaming is an extension of IIS Media Services, which enables the Silverlight client to adapt to the bandwidth of streaming media through HTTP, through special processing of video source files (such as wmv and other common video file formats), multiple video file copies of different versions are generated on the server according to different bandwidth requirements, after IIS receives a request from the Silverlight client, it determines which video file copy is sent to the client through streaming media. This process is completely dynamic, that is, when the bandwidth of the client changes, the copy of the video file that transmits the streaming media will also change accordingly. If the bandwidth of the current client is below kbps, the current copy of the streaming media file may be 280kbps. When the bandwidth of the client increases to 1 Mbps, the current copy of the streaming media file may be 1.5mbps. Do you think it's amazing? Of course, all these require support from IIS 7 and Silverlight 3.0.


What do you need?

In fact, many people have already introduced the smooth streaming technology before I studied it. It seems that it is not so strange! Here is some information I have collected on the Internet. You can first understand:



Basically, some tools are essential before we start smooth streaming. Otherwise, we will not be able to perform subsequent work.

1. IIS 7.As far as I know, IIS 7 is basically supported in Windows operating systems after Vista. If you do not find "Internet Information Services (IIS)" in the "Administrative Tools" of the operating system) manager, you need to add it by adding windows feature. My system environment is Windows 7. below is.

The installation of IIS 7 on Vista and Windows 2008 may be different. Note that to install IIS 7 on Windows 2008, you must add a server role in the server management interface.

2. Smooth streaming plug-in.That is, IIS Media Services 3.0, which has been downloaded from official sites. Download extension in the upper-right corner of the page to download or install smooth streaming. Note that the versions of 32-bit and 64-bit machines are different. If you choose "using the Microsoft Web platform installer" for installation, the web platform installer is installed in IIS 7, and then the smooth streaming is installed online. After the installation is successful, you need to re-open the management interface of IIS 7 and click the site, in the function view on the right, a media service category is displayed. The following three plug-ins are added: Bit Rate throttling, live smooth streaming, and smooth streaming.

Here, I have installed IIS Media Services 3.0, so the options for selecting and installing IIS Media Services 3.0 in web platform installer are grayed out. In addition, you can install many other IIS 7 plug-ins through web platform installer, which are also a plug-in of IIS 7. After installation, they will appear in the management category on the IIS 7 management interface, in the beginning of this article.

In addition to installing smooth streaming through web platform installer, you can also directly download the installation package for installation. The downloaded smooth streaming plug-in is an MSI package, iismedia32.msi (the 64-bit version should be iismedia64.msi ).

3. Microsoft Expression encoder 3.In fact, encoder 2 is also acceptable, but I personally recommend using encoder 3, which saves you a lot of trouble and provides more functions.

4. Visual Studio 2008 and Silverlight 3.0.This is basically a must-have. If you are a Silverlight developer, I will not talk about it here.

Now, after the preparation is complete, let's start using smooth streaming in Silverlight 3.


How to start?

We all know that to play a video in Silverlight, you need the support of the mediaelement control. In previous applications, you only need to specify a source attribute for this control, you can tell the mediaelement control the local or remote video file (or video service) address, and then use media template (this can be automatically generated or fully customized through encoder) buttons, progress bars, and so on. This process is relatively simple. Of course, if you want to do something cool, you may have to pay off the cost.

To play a video through smooth streaming, the format of the video is required, which is why we need Microsoft Expression encoder. With encoder, we can convert the video source file to the file format supported by the smooth streaming. This step is shown in the above two sections.ArticleThey all have a detailed introduction (see the section "What Do You Need"). In fact, I have also referred to it. Here I will give a brief introduction.

Open encoder, import the video file to be converted, select encoder panel on the right, and set output format to IIS smooth streaming.

You can also set other settings, such as setting the start and end times of the video in the clip panel, setting the audio (mode, bit rate, audio channel, etc.), and expanding the video node, you can also increase or decrease the number of copies required by the smooth streaming. These copies correspond to the bandwidth range of each client.

It is best to set an output template in the output panel, so that after the encoder converts the video, it will automatically generate a Silverlight example based on the template you selected to play the converted video, the automatically generated xap file will be used later. Note the output path. After the conversion, We need to copy the corresponding file to this directory.

The conversion time depends on the size of the selected video file. Generally, the conversion time is relatively long, so you may have to be patient. After the conversion is complete, go to the output directory of encoder. If you haven't modified this path, it should be under "My document-expression. For example, this is the Conversion Result on my machine:

According to your settings in encoder, the video file is converted to a file named by bandwidth range, and the suffix is. ismv. There is also an ism file and an ismc file, both of which are XML files. You can use NotePad to open them. You will see some configuration information, and the ISM file is a Server Parsing file, it is used to describe the relationship between different bit rate files on the hard disk, while the ismc file is the client-side parsing file, which is used to determine which bit rate of the explanatory file to download to the client, this includes describing available bit rate videos, decoder used, and video resolution. We don't need to study what the two files are, because they are all used by smooth streaming. Templates, mediaplayertemplate. xap, and smoothstreaming. xap. Here, we will introduce what we need in the smoothstreaming. xap file.

In addition, to quickly demonstrate smooth streaming, we can directly download and install the IIS smooth streaming player development kit, which will provide the xap file to be used for the demonstration as well as the page.


Create site

Of course, to make smooth streaming work, we need to set up an smooth streaming site on the server. Very easy! First, copy all ismv files and ISM and ismc files in the files converted by encoder to the physical directory of the website you want to create. Follow the instructions on the official website wizard (you can download the PDF or Doc wizard documents on the official website, but only in English). There are two smooth streaming solutions available, open IIS 7 and click the site we created. The live smooth streaming and smooth streaming plug-ins are displayed under the media services category in the function view on the right, in fact, they are the serving on-demand smooth streaming (On-Demand smooth streaming) and serving live smooth streaming (Real-Time smooth streaming) mentioned in the Wizard ), the setup of these two solutions in the Wizard is very detailed, including how to use encoder to convert video files and how to publish video files, which makes the whole process very cumbersome, in fact, this is not so troublesome!

First, you can use WebDAV to publish video files in encoder. However, it is troublesome to Configure permissions and authentication on IIS, we can manually copy the conversion file to the website (just copy it, nothing else ).

Then the smooth streaming is released.

Let's talk about the release of live smooth streaming. Open live smooth streaming in IIS, click "add", enter the name of the live smooth streaming file you want to create in the pop-up window, and set live source type to push, other options, such as title and estimated duration, are not required.

Click Start publishing point in actions on the right. Then, an isml file named after you is generated under the Physical directory of the website. Do you still remember the IIS smooth streaming player development kit you downloaded before? Producer, smoothstreamingsampleplayer. xap.

Switch to Windows Command mode and go to the directory where the website is located. Execute the following command:

Pushencoder <URL-of-publishingpoint> <ISM-File>

The Execution Process on my machine is as follows:

You may have to wait a little while, because the command execution process takes a little time and you must wait until the command is fully executed. Now, open your browser, enter the address of your site, and then follow the URL of/livesmoothstream. isml/manifest. You will see that the parsing file of live smooth streaming server has been generated.

Now, basically, the video has been successfully played. When you see the above picture, it means that your live smooth streaminghas been successfully set up. Next, you can set a playback address in the default.html file to play the video. Start default.html with the export script, find the mediasource attribute of the Silverlight control, and change the following address to "http: // localhost: 77/livesmoothstream. isml/manifest. Note that "localhost: 77" is the website address on my machine. It may be different from yours, "livesmoothstreaming. isml is the name of the parsing file for the live smooth streaming server you created. Now you should be able to see your published video in the browser, because we directly use the Player provided by IIS smooth streaming player development kit, therefore, you only need to modify the address to directly play the video. In this player, you will see that the quality of the video will change as the bandwidth of the client changes, this is exactly the function provided by live smooth streaming.

Well, I don't know if you have successfully set up a site like me. If you haven't succeeded, you may have to check it carefully. Maybe something went wrong, if you can watch the video, congratulations, you have learned how to publish live smooth streaming. Do you still remember when I mentioned that live smooth streaming is "real-time smooth streaming? Yes, this method can provide real-time video playback online, but there is a problem. When we restart IIS (the worst thing is when we restart the machine), we need to re-release the isml parsing file, that is to say, the pushencoder command is used to re-generate the content of the isml file. I don't know why I have to do this, but it does bring a lot of trouble. Next let's take a look at smooth streaming (smooth streaming on demand.

This is a simple comparison. without creating any files on iis, we only need to specify the Silverlight source attribute in the default.html file as this address. "http: // localhost: 77/wildlife. ISM/manifest. Similarly, you may need to modify "localhost: 77" and "wildlife. ISM ". Now, you can also see the video in the browser, basically there is no difference, but this method is not real-time.


Create your own smooth streaming player

We used the Player provided by IIS smooth streaming Player Development Kit for demonstration above. If you already have a player in your Silverlight project, how can you make it play the video stream provided by smooth streaming? Maybe you just need to direct the source attribute of the mediaelement control to the address we introduced above, but as a matter of fact, I have tried to make some changes to the Code. Indeed, there are some materials for your reference:





In fact, it is not very troublesome, but some preparation work should be done. First, you need to use the adaptivestreamingsource object in your Silverlight project. This object does not exist in the standard class library of Silverlight 3.0. What should I do? Remember that I asked you to copy the xap file in the file generated by encoder to the root directory of the website? The smoothstreamingsampleplayer. xap is now useful. Change the suffix of this file to zip (in fact, the xap file is a compressed Package). Open it and see it? It contains the two class libraries we will use, pluginmssctrl. dll and smoothstreaming. dll, and reference them to your Silverlight project.

Now you can modify your Silverlight code with confidence. The following is my example. It is difficult to understand it!

< Usercontrol X: Class = "Smoothstreamingtest. mainpage"
Xmlns = "Http://"
Xmlns: x = "Http://"
Xmlns: d = "Http://" Xmlns: MC = "Http://"
MC: ignorable = "D" D: designwidth = "640" D: designheight = "480" >
< Grid X: Name = "Layoutroot" >
< Mediaelement X: Name = "Mediaelement" Loaded = "Mediaelement_loaded" />
</ Grid >
</ Usercontrol >


Using System. Windows. controls;
Using System. Windows. documents;
Using System. Windows. input;
Using System. Windows. Media;
Using System. Windows. Media. animation;
Using System. Windows. shapes;
Using Microsoft. expression. encoder. adaptivestreaming;

Namespace Smoothstreamingtest
Public   Partial   Class Mainpage: usercontrol
Private   String Uristring =   " Http: // localhost: 77/wildlife. ISM/manifest " ;
Private Adaptivestreamingsource mainsrc =   New Adaptivestreamingsource ();

PublicMainpage ()
Initializecomponent ();

mainsrc. mediaelement = mediaelement;
mainsrc. manifesturl = New uri (uristring );

Private VoidMediaelement_loaded (ObjectSender, routedeventargs E)
Mainsrc. startplayback ();

We construct an adaptivestreamingsource object, direct its manifesturl attribute to our smooth streaming publishing address, and direct its mediaelement attribute to the mediaelement control instance, then you can use its startplayback method to play the video. Isn't it easy? However, you need to note that we can directly start and debug the Silverlight project in Visual Studio. If you direct the video address to the smooth streaming release address, at this time, you cannot see the video during debugging in visual sudio, but you must publish the website to IIS. This is also strange to me. It is clear that only the smooth streaming video publishing site receives the request. It has nothing to do with the requested site, but you must do so to see the video.


Cross-origin access problems

There is another problem here. If your site publishing address and the smooth streaming publishing address are not one site, or are not on the same server, the smooth streaming request will fail. In fact, this is not a problem of smooth streaming itself, it is a problem caused by Silverlight. If you encounter such a problem, you can create a file named clientaccesspolicy. xml under the Physical root directory of the smooth streaming release site and write the following content into it:

<? XML version = "1.0" encoding = "UTF-8" ?>
< Access-Policy >
< Cross-Domain-Access >
< Policy >
< Allow-from HTTP-request-headers = "*" >
< Domain Uri = "Http: // sitename" />
</ Allow-from >
< Grant- >
< Resource Path = "/" Include-subpaths = "True" />
</ Grant- >
</ Policy >
</ Cross-Domain-Access >
</ Access-Policy >

The URI of the domain node determines which request sites are allowed to access resources. You can add multiple domain nodes. In this example, specify http: // sitename/this site will be allowed to access resources, or simply use<Domain uri = "*"/>Allow access by all sites. Create a file named crossdomain. XML with the following content:

<? XML version = "1.0" ?>
<! Doctype cross-domain-Policy System "" >
< Cross-Domain-Policy >
< Allow-http-request-headers-from Domain = "*" Headers = "*" />
</ Cross-Domain-Policy >

Similar to the clientaccesspolicy. xml file, you can also set it to allow some sites to access resources, or use "*" to allow access by all sites. This is a solution to Silverlight cross-origin resource access.


A small gain

People who develop. NET should have used the reflector decompilation tool more or less. This is a great. Net decompilation tool that can be restored almost.Source codeAnd it also supports some plug-ins that can be extended. Now we have another plug-in that can decompile Silverlight, silverlightbrowser, which many friends may have heard. However, I would like to mention here that if you need it, you can download the link provided at the end of this article to facilitate research and learning about Silverlight.

Download silverlightbrowser and decompress it. There are two files, one DLL and one config. Open reflector and click "view, add-ins... ", click" add "in the pop-up dialog box, and select the DLL file decompressed by silverlightbrowser. The silverlightbrowser plug-in is installed in reflector. Now let's take a look at how to use silverlightbrowser.

In reflector, select Browse Silverlight page under tools. In the Silverlight browser window opened on the right, we need to open a URL address. Of course, this address should contain Silverlight. Click Go, the Silverlight browser window will preview the Silverlight decompile the resources and code in the xap package at the same time, as shown in.

Of course, we can also manually decompile the objects in the class library. Expand the resources node under the Assembly node, and click the node in it. You can view and copy the XAML file. This plug-in is a great plug-in, except for the ability to decompile the DLL in the xap package, at the same time, you can decompile the XAML code. if used properly, you can completely restore the entire Silverlight project.



The appearance of smooth streaming technology is not too long, but as a plug-in of IIS 7, it extends the features of media services, this makes smooth video playback easy on Silverlight. At the same time, only a small number of changes are required to port the old version of Silverlight to support smooth streaming technology, which greatly reduces the development workload and is worth promoting and applying.


Download the silverlightbrowser plug-in

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.