Distributing a License with a Media File

You can deliver a license for a media file at the same time or before the media file is downloaded by a consumer. The consumer must have a media player, such as Microsoft® Windows Media™ Player version 6.2 or later, that can play packaged media files and that can be embedded in a Web browser.

This article contains information about scenarios in which you would deliver licenses with media files, how the process works, sample code to show you how to modify the ASP script, and where to go for additional information, as follows:

  • Examples of delivering licenses with media files

  • The process of delivering licenses before the media file

  • Sample code

  • Additional information

On This Page

Examples of delivering licenses with media files Examples of delivering licenses with media files
The process of delivering licenses before the media file The process of delivering licenses before the media file
Sample code Sample code
Additional information Additional information

Examples of delivering licenses with media files

When you use the Microsoft® Windows Media™ Rights Manager Web site to distribute packaged media files, consumers must download the files and then start the license acquisition process by trying to play them. Licenses are issued after consumers register. However, by modifying the Active Server Pages (ASP) script that runs this process, you can issue licenses before or at the same time that the media files are downloaded.

This feature can be used in a number of ways, as described in the following examples:

  • A consumer purchases a song on your Web site, and you deliver the license with the media file to reduce the number of steps for the consumer. In the original scenario, the consumer would have to visit your site once to purchase and download a song, and again to register for the license.

  • You set up a subscription (a set of media files that share a license), and deliver the license when the consumer subscribes. Then the consumer can download the media files in the subscription at any time. In the original scenario, the consumer would have to download and play a media file to start the license acquisition process.

  • You place packaged media files on a server running Microsoft® Windows Media™ Services for streaming, and deliver the license when a consumer requests a media file. In the original scenario, the consumer would have to acquire the license in a separate process.

  • You want to promote a song, so you deliver the license for it when another license is issued. Then, the consumer can download and listen to the song without having to go through the license acquisition process for the promotional song.

The process of delivering licenses before the media file

By default, the license acquisition process is triggered when a consumer tries to play a packaged media file for the first time. However, if you want to deliver a license before the consumer has downloaded a media file (or at the same time), you can duplicate the license acquisition process without making the consumer aware of it.

In the code example in this article, an invisible frame appears in the consumer's Web browser (although you can implement this process without using frames). The frame contains an embedded player that opens the media file for which you want to issue a license. Parameters are set so that the media file is loaded but not played, and consumer feedback (such as registration information) is not required. The player checks for a license; if one is not found, Windows Media™ License Service issues a license and stores it on the consumer's computer without requesting any registration information. This result is similar to that of the standard license acquisition process, but is completely invisible to the consumer.

If for some reason this process fails (for example, because the consumer does not have a player that can be embedded in a Web browser), the standard license acquisition process is used. When the consumer tries to play an unlicensed media file, the player opens the license acquisition URL and a license is automatically issued. No problems occur if a license is issued twice for one media file.

Sample code

The following sample code shows you how to modify the Windows Media Rights Manager Web site so that when a consumer downloads a media file, a license for it is issued simultaneously, without prompting the consumer for registration information. When a consumer clicks a link on the Web site's downloads page, the Web browser opens the Downloads.asp page with content_ID as a parameter. This page displays download instructions to the consumer, and it contains the invisible frame. The download process begins when the File Download box automatically opens and the consumer specifies where to save the media file. While the media file is being downloaded, the license for it is issued and stored on the consumer's computer. Then, the consumer can play the file without having to go through the license acquisition process.

Note: If a consumer is using Microsoft® Internet Explorer version 4.0, the Download4.asp page appears instead of Download.asp. The new process is not implemented unless you write script to modify Download4.asp as well.

This sample contains new or modified code for the following pages:

  • Download.asp. This page appears after a consumer clicks a media file to download it. This page processes download requests by finding and sending the appropriate media file, and then entering the download transaction into the drm_download_statistics table in the Windows Media Rights Manager database.

    This page uses a double frame; the top frame displays instructions (Instructions.asp), and the invisible bottom frame is used to deliver the license and embed the player (Licdel.asp).

  • Instructions.asp. This page contains instructions, and appears in the top frame of Download.asp.

  • Licdel.asp. This page delivers the license and embeds the player. This page is used in the invisible bottom frame of Download.asp.

    Note: The file name parameter sent by the player during license acquisition points to the name of the Web page containing the embedded media player, not the name of the media file opened by the player.

  • Cookies.asp. This page is used in the registration process. So that the license is issued automatically and invisibly with the media file, you must disable the part of the process that prompts the consumer for registration information. You can disable this process by changing one line of code in this page.

To use the sample code, follow the instructions for each of the following files. By default, the pages for the Windows Media Rights Manager Web site are located in C:\Inetpub\Wwwroot\Windows Media.

Download.asp

In a text editor, open Download.asp. Replace the contents of this file with the following code. However, if you want to be able to revert to the original functionality, back up the original Download.asp file first.

<% REM ####################################################################%>
<% REM                                                                     %>
<% REM   Download.asp                                                      %>
<% REM   Microsoft Windows Media Rights Manager v1.0                       %>
<% REM                                                                     %>
<% REM   Copyright (c) 1999 Microsoft Corporation.  All rights reserved.   %>
<% REM                                                                     %>
<% REM ####################################################################%>

<%option explicit%>
<%Response.Buffer = True%>
<%
Dim content_id

content_id = Request("content_id")
%>
<HTML>
<FRAMESET ROWS="100%,*">
<FRAME SRC="instructions.asp?content_id=<%= content_id %>">
<FRAME SRC="licdel.asp?content_id=<%= content_id %>">
<noframes>
<body>                    
<p>This page uses frames, but your Web browser does not support them.</p>
</body>
</noframes>
</FRAMESET>
</HTML>

Licdel.asp

In a text editor, create a new document, copy and paste the following code into it, and then save the file to the Web site directory as Licdel.asp.

<%
 'Request the content_id from the previous page
 Dim content_id, strURL, hResult
 content_id = Request.QueryString("content_id")
 'If the content_id is valid, then download the file corresponding 
to that content_id.

 If content_id <> "" Then
 Dim objInstMgr
 on error resume next
 Set objInstMgr = CreateObject("InstanceManager.DRMInstanceManager")
 If Err.number = 0 Then
 'The strURL will contain the path of the encrypted file.
 
strURL = objInstMgr.DownloadFile 
(Application("DBSERVER"),Application("DBDATABASE"),Application("DBUID"),
Application("DBPASSWORD"),content_id, "")
If  Err.number = 0 Then
%>
<!-- #include file="dbbegin.asp" -->
<%
'Make an entry in the database everytime a download happens.
objCmd.CommandText = "insert into drm_download_statistics 
(content_id) values (" & content_id& ")"
objCmd.CommandType = adCmdText
objCmd.Execute
%>
<!-- #include file="dbend.asp" -->
<%	 
'Encode the path of the file and download it!
strURL = Server.HTMLEncode(strURL)
'Response.Redirect strURL
end if
end if
end if	 	 	 	 	 	 	 	 
%>
<HTML>
<BODY>
This frame is supposed to be hidden, but is shown here to 
indicate what is happening. 
<OBJECT ID="MediaPlayer" WIDTH=0 HEIGHT=0 
CLASSID="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95" type="application/x-oleobject">
<PARAM NAME="FileName" VALUE="<%= strURL %>">
<PARAM NAME="ShowDisplay" VALUE="FALSE">
<PARAM NAME="AutoStart" VALUE="FALSE">

<EMBED HIDDEN NORESIZE Type="application/x-mplayer2"
src="<%= strURL %>"
ShowDisplay=0
AutoStart=0
HEIGHT=5
WIDTH=5>
</EMBED>
</OBJECT>  
</BODY>                    
</HTML> 

Instructions.asp

In a text editor, create a new document, copy and paste the following code into it, and then save the file to the Web site directory as Instructions.asp.

<%
'Request the content_id from the previous page
Dim content_id, strURL, hResult
content_id = Request.QueryString("content_id")

'If the content_id is valid, then download the file corresponding to that content_id.
If content_id <> "" Then
Dim objInstMgr
on error resume next
Set objInstMgr = CreateObject("InstanceManager.DRMInstanceManager")
If Err.number = 0 Then

'The strURL will contain the path of the encrypted file.
strURL = objInstMgr.DownloadFile 
(Application("DBSERVER"),Application("DBDATABASE"),Application("DBUID"),Application
("DBPASSWORD"),content_id, "")
If  Err.number = 0 Then
%>
<!-- #include file="dbbegin.asp" -->
<%
'Make an entry in the database everytime a download happens.
objCmd.CommandText = "insert into drm_download_statistics 
(content_id) values (" & content_id& ")"
objCmd.CommandType = adCmdText
objCmd.Execute
%>
<!-- #include file="dbend.asp" -->
<%	 
'Encode the path of the file and download it.
strURL = Server.HTMLEncode(strURL)
'Response.Redirect strURL
end if
end if
end if	 	 	 	 
%>

<HTML>
<TITLE> Download Instructions </TITLE>
<BODY>
<META HTTP-EQUIV="REFRESH" CONTENT="2; URL=<%= strURL %>">
You need Windows Media Player version 6.2 or later to play the media file you 
are downloading. If you don't have this player, you can download it from 
<A HREF="https://www.microsoft.com/windows/mediaplayer/download/beta.asp">
https://www.microsoft.com/windows/mediaplayer/download/</A>.
After you download the media file, open it by finding the file you saved and 
then double-clicking it. Or, if the <b>Download complete </b>dialog box 
is still open, click <b>Open</b>.
</BODY>
</HTML>

Cookies.asp

By default, the only time a consumer is not prompted to enter registration information is when a cookie on the consumer's computer is found that identifies the consumer as a registered visitor. So, to prevent the license acquisition process from prompting the consumer for registration information, set the e-mail address variable to that of a known (registered) address. Then, the Cookies.asp page sets a flag for Registration.asp to issue a license right away. Otherwise, the consumer is prompted for an e-mail address and the license is not issued invisibly.

To disable the registration process

  1. Open Cookies.asp in a text editor.

  2. Find the following line:

email = Request.Cookies("email_address")

  1. Replace email_address with any e-mail address that is currently registered (present in the Windows Media Rights Manager database in the drm_user_information table).

Additional information

To learn more about Windows Media Rights Manager, see Windows Media Rights Manager Help. Windows Media Rights Manager is available for download from the Windows Media Technologies page at the Microsoft Web site ( https://www.microsoft.com/windows/windowsmedia/default.aspx ).

Packaging Media Files in Batches https://msdn.microsoft.com/workshop/imedia/windowsmedia/Batchpac.asp

Detecting a Player on a Consumer's Computer https://msdn.microsoft.com/workshop/imedia/windowsmedia/Clientdet.asp

Integrating Windows Media Rights Manager with Other Applications https://msdn.microsoft.com/workshop/imedia/windowsmedia/Integrat.asp

Setting Up Media Files for Subscriptions and Streaming https://msdn.microsoft.com/workshop/imedia/windowsmedia/Substream.asp

Comparing Server Configurations for Issuing Licenses https://msdn.microsoft.com/workshop/imedia/windowsmedia/Scalability.asp