Click Here to Install Silverlight*
United StatesChange|All Microsoft Sites
Windows Media Player 9 Series
|Windows Media Worldwide

Deploying Windows Media Technologies at KING FM

David Wrede
Microsoft Corporation
February 2004

Applies to:
Microsoft® Windows Media® Player 9 Series
Microsoft Windows Media Encoder 9 Series
XML Web Services

Contents

Introduction

KING FM Leave this Web site is a classical radio station based in Seattle. In addition to broadcasting over the air, they have been broadcasting on the Internet since 1995. Since that time,
Feedback
E-mail us with your comments and feedback about this article.
 
Abstract
KING FM Leave this Web site, a Seattle radio station, is one of largest Internet broadcasters in the country. With their recent adoption of Windows Media technologies, they looked for new ways to bring in advertising revenue as well as enhance their users' experiences while streaming content. This whitepaper explains the technologies involved and how they were used together.

(8 printed pages)
they have become one of the largest Internet radio stations in the country. Although KING FM was able to provide their users with a great listening experience, they had no way of taking advantage of new technologies that would allow them to provide a richer user experience and to generate more ad revenue. In the fall of 2003, KING FM worked with Microsoft® to deliver these using various components based on Windows Media® technologies and XML Web services.


Overview of the Components

In order to provide users with a rich, dynamic streaming experience, several software and hardware components were used to implement the new KING FM streaming solution. The software components were based on the following technologies:
  • Windows Media Encoder 9 Series. We used Windows Media Encoder because it can send script commands through a script stream to Windows Media Player running on a client's computer. These script commands can cause URL flips, display text inside the Player, or trigger custom events that the Player can respond to through a scripting language.
  • Windows Media Player 9 Series. We used Windows Media Player because it allowed us to show an embedded Web page inside the Now Playing pane. We then used the Windows Media Player ActiveX® control in that embedded Web page to access to the Windows Media Player 9 Series object model. This, in turn, allowed the components to respond to custom script commands sent by Windows Media Encoder.
  • XML Web services. The XML Web services technology enabled script code on a Web page to query information in a database and then send the results of that query back to the Web page. These results could be cached so that subsequent requests for the same data would not slow down the server running the XML Web service.

Some of the hardware components could be combined, but an implementation similar to what we installed at KING FM would require an encoder, a media server or content delivery network (CDN), a Web server, and a database server running Microsoft SQL Server 2000 or higher.

These software and hardware components are at the center of the new Windows Media 9 Series streaming solution at KING FM.

Back to the top of this page Back to the top


How the Components were Integrated

The following flowchart shows how the client receives the enhanced experience solution.

Figure 1. Flowchart of enhanced experience solution.
Figure 1. Flowchart of KING FM Enhanced Experience Solution

  1. The client clicks on a link to an .asx file, which opens a Web page in the Now Playing pane of Windows Media Player and also connects the Player to the live broadcast streamed from the CDN.
  2. The script command tool accesses two text files that contain playlist and ad-logging information. The script command tool then sends composer or ad information remotely through a script stream to the encoder. This script data is then transferred to the client along with the live broadcast. Script information is sent to the encoder every 30 seconds so that, if a user connects to the live broadcast, she will only have to wait a maximum of 30 seconds before their content window is updated.
  3. JScript code in the Web page parses the pseudo-XML code that is sent by the script command tool and displays that information on the Web page through DIV elements. The Web page then calls an XML Web service running on the Web server to gather any extra information about the composer or ad that is displayed. The database returns the results of the call, and the results are displayed on the Web page running inside the Now Playing pane.

The following illustration shows an example of what the user sees after connecting to the KING FM Windows Media broadcast. Everything but the content area and the banner ad at the bottom of the window is static.

Figure 2. Windows Media Player 9 Series with new embedded Web page.
Figure 2. Windows Media Player 9 Series with new embedded Web page.

Back to the top of this page Back to the top


Hardware Components

The following hardware components were used in the KING FM Windows Media solution.
  • Encoder. KING FM set up a dedicated encoding computer running Windows Media Encoder 9 Series to encode all of their digital media. They created a custom encoding profile that encodes a live broadcast along with a script stream for the custom script commands that are sent to the user through the CDN.
  • Content Delivery Network (CDN). KING FM chose to use a CDN to deliver their broadcasts to users because of the increased bandwidth that CDNs can provide. The CDN connects to the encoding computer and pulls the broadcast stream to its delivery network before sending the stream to clients. This KING FM Windows Media solution does not require any additional setup on the part of the CDN because the CDN is simply relaying the audio and script streams it receives from the KING FM encoder.
  • Web server. To run the XML Web service on a Web server, KING FM partners with a Web host that runs Windows®-based servers and supports the .NET Framework and ASP.NET.
  • Database server. The Web host for KING FM employs a separate server running SQL Server 2000 for database support. The XML Web service calls into the database by using a stored procedure. This helps to speed up performance and limits the ability of a malicious user to gain access to information in the database.

Back to the top of this page Back to the top


Software Components

The following sections explain each of the components in detail and describes how they work together.

Client .asx File

An .asx file is used to load an embedded Web page inside the Now Playing pane of Windows Media Player 9 Series, in addition to connecting to a live stream. The following example code from an .asx file shows how the Web page EmbeddedPage.htm is specified to display before the Player connects users to a stream specified by the ENTRY element.

<ASX version="3.0">
    <PARAM NAME="HTMLView" 
        value="http://www.contoso.com/EmbeddedPage.htm"/>
    <ENTRY>
        <REF href="http://www.contoso.com/Live"/>
    </ENTRY>
</ASX>
Setting the NAME attribute to HTMLView lets you to embed any Web page inside of the Now Playing pane of the stand-alone Player. For more information on utilizing the HTMLView feature, see Using the Windows Media Player 9 Series HTMLView Feature on the MSDN® website.

Script Command Tool

The script command tool performs many functions. By accessing information from a constantly updated ad-logging file and a pre-determined playlist file, it determines what information to pass through into the script stream.

To pass the script stream along to the user, the script command tool needs access to a running instance of Windows Media Encoder. A WMEncoderAgent object is created on the remote encoding machine.

Set EncoderAgent = CreateObject("WMEncAgt.WMEncoderAgent",_ 
    "computer name")
The string "computer name" is generic and would be replaced by the name of the actual remote encoding computer. UNC names, DNS names, and IP addresses may be used.

Note   The remote encoding computer must have the correct DCOM configuration settings enabled in order for the script command tool to access it. For more information, see Security Considerations.

After the WMEncoderAgent object is created, an IWMEncoderNamesCollection object must be created and assigned the collection of currently running WMEncoder objects.

Set EncoderNames = EncoderAgent.EncoderNamesCollection
In the KING FM implementation there is only one instance of Windows Media Encoder running, so the script command tool retrieves it and assigns it to a local WMEncoder object variable. If there were more than one instance running, then the tool would have to cycle through all of the instances until it found the name of the encoder to which it should connect.

Set Encoder = EncoderAgent.GetEncoder(EncoderNames.Item(0))
The script command tool can now remotely administer the encoding machine and place script commands in the script stream. The following example shows how the tool sends a custom command named "PLAYLISTINFO" down to the user.

Encoder.SendScript(0, "PLAYLISTINFO", "<CustomTag>This text is handled by 
client-side scripting code.</CustomTag>")
For playlist information, the tool used by KING FM sends out script commands using the following pseudo-XML structure:

<F2>Composer</F2>
<F3>Title of Song</F3>
<F4>Performed By</F4>
<F5>Extra Information></F5>
<F6>Label</F6>
Note   In the KING FM solution, there are no line breaks between the fields. They are shown here for readability.

The various fields (F2, F3, and so on) are generic so that if KING FM wants to re-order the content on the Web page, they don't have to re-order the corresponding fields as well.

Note   There is an F1 field that contains the time that a piece begins, but it is only used by the script command tool to decide when to update the content information on the Web page.

The script command tool sends out a similar script command for ads, but there is only one field that is sent instead of several.

Embedded Web Page

The Web page referenced in the client .asx file will be embedded in the Now Playing feature of Windows Media Player. An embedded Windows Media Player 9 Series ActiveX object handles custom events that are triggered when script commands are detected in the live audio stream.

Scripting code is used to capture the custom script commands sent by the script command tool. The Web page includes JScript code that responds to any script commands sent to the embedded ActiveX object.

<script language="jscript" FOR="Player" 
EVENT="ScriptCommand(scType, scParam);">
The JScript code tests whether the custom script command is named PLAYLISTINFO. If the script command is PLAYLISTINFO, the code calls the function ParseScriptCommand and assigns the various elements (Composer, Title, PerformedBy, and Label) to corresponding HTML table cells.

if(scType == "PLAYLISTINFO")
{
    ParseScriptCommand();
    Composer.innerHTML = RegExp.$1;
    Title.innerHTML = RegExp.$2;
    Performer.innerHTML = RegExp.$3; + "<br>" + RegExp.$4;
    Label.innerHTML = RegExp.$5;
    GetComposerInfo();
}
A similar conditional statement tests for custom script commands named "ADINFO."

The function ParseScriptCommand uses regular expressions to retrieve data from the custom script command named PLAYLISTINFO. All of the data between the pseudo-XML tags are placed into individual patterns in an array. This allows each pattern to be assigned to a local variable and displayed in any number of styles.

function ParseScriptCommand() 
{
    var regularExpression = /\<F2\>(.*)\<\/F2\>\<F3\>(.*)\<\/F3\>
    \<F4\>(.*)\<\/F4\>\<F5\>(.*)\<\/F5\>\<F6\>(.*)\<\/F6\>/
    var arr = regularExpression.exec(scParam);
}
Note   Regular expressions in JScript must not have any line breaks in them. Line breaks were added to this example regular expression for readability.

The function GetComposerInfo passes the name of the current composer to the XML Web service. This function is explained in more detail in the next section.

XML Web Service

The XML Web service looks up composer or ad information in a database and displays that information to users in the embedded Web page. In order to implement this functionality, scripting code must be added to the embedded Web page to take advantage of the Web service.

In the body of the embedded Web page, a DIV element must be created for the XML Web service and the behavior must be set.

<DIV id="myWebService" style="BEHAVIOR: url(webservice.htc)"></DIV>
The WebService behavior, which is encapsulated in an .htc file, enables client-side scripting code to invoke remote methods exposed by Web services. The webservice.htc file is located in the XML Web service directory on the Web server.

Before the embedded Web page makes any calls to the XML Web service, it must be initialized. The following example shows how we implemented the Init function.

function Init()
{
    myWebService.useService(
        "http://MyWebServer/WebService/WebService.asmx?WSDL",
        "ExampleWebService");
}
This function is called during the OnLoad event raised by the Web page. The function is declared in the BODY element of the Web page.

<BODY onload="Init();">
The GetComposerInfo function is called in the conditional statement shown in the previous section. The following code shows how the name of the composer (from the first regular expression pattern) is passed into the GetMoreInfo method on the XML Web service.

function GetComposerInfo()
{
    myWebService.WebService.callService(ComposerResult, 
        "GetMoreInfo", RegExp.$1);
}
In the implementation of the GetMoreInfo method, a connection is made to the KING FM database. Using the following stored procedure located in the database, the GetMoreInfo method is able to quickly and securely query the database for more information on the composer.

CREATE PROCEDURE ComposerProcedure @name char(255) AS
BEGIN
    DECLARE @select_stmt varchar(255)
    SET @select_stmt='SELECT Biography, Description, Image, RelatedBooks, 
RelatedCDs FROM Composers WHERE Composer= 
(''' + replace(@name,',',''',''') + ''')'
    EXECUTE (@select_stmt)
END
GO
Once that information is returned to the GetMoreInfo method, it formats the data in the same pseudo-XML structure that the script command tool uses.

The callback function, ComposerResult, takes the pseudo-XML code and formats the content so that it can be displayed in the embedded Web page. ComposerResult is declared in the GetMoreInfo function and defined as follows:

function ComposerResult(result)
{
    if(result.value != "")
    {
        RegExp.$1 = "";
        RegExp.$2 = "";
        RegExp.$3 = "";
        RegExp.$4 = "";
        RegExp.$5 = "";

        var regularExpression = /\<F1\>(.*)\<\/F1\>\<F2\>(.*)\<\/F2\>
              \<F3\>(.*)\<\/F3\>\<F4\>(.*)\<\/F4\>\<F5\>(.*)\<\/F5\>/
        var arr = regularExpression.exec(result.value);

        ComposerLink.href = RegExp.$1;
        Description.innerHTML = RegExp.$2;
        Picture.src = RegExp.$3;
        RelatedBooks.innerHTML = RegExp.$4;
        RelatedCDs.innerHTML = RegExp.$5;
    }
    else
    {
        ComposerLink.href = "http://www.contoso.com";
        Description.innerHTML = "";
        Picture.src = "DefaultPic.jpg";
        RelatedBooks.innerHTML = "";
        RelatedCDs.innerHTML = "";
    }
}
Note   Regular expressions in JScript must not have any line breaks in them. Line breaks were added to this example regular expression for readability.

Inside the ComposerResult function, regular expressions are used again to parse the pseudo-XML code. DIV elements on the embedded Web page are updated with new text or graphics. If no results were returned from the database query, default text and graphics are displayed to the user.

Back to the top of this page Back to the top


Security Considerations

The script command tool can run on any remote computer and attach itself to a running instance of Windows Media Encoder, but certain DCOM settings must be configured. For more information on this, see the Specifying DCOM Security Settings topic in the Windows Media Encoder 9 Series Software Development Kit (SDK).

The XML Web service follows various security guidelines when in use on a Web server. To learn how to increase the security of your Web services, see chapter 12 of Improving Web Application Security: Threats and Countermeasures on the MSDN website.

Along with making your XML Web service secure, you should make sure your data access code is secure as well. For more information, see chapter 14 of Improving Web Application Security: Threats and Countermeasures on the MSDN website.

If you are hosting your database server, see chapter 18 of Improving Web Application Security: Threats and Countermeasures on the MSDN website to learn how to minimize any threats to your server.

Back to the top of this page Back to the top


For More Information


Back to the top of this page Back to the top



© 2008 Microsoft Corporation. All rights reserved. Contact Us |Terms of Use |Trademarks |Privacy Statement
Microsoft