Web Playlists for IIS 7.0 - Extending Web Playlists through Custom Providers

By Vishal Sood

April 21, 2008

Web Playlists allows you to extend its default behavior by writing custom providers. It provides a COM interface that can be implemented in either a .NET-based or native custom provider. This document contains the following sections:

Writing custom providers

Implementing the interfaces

The interfaces included in the Playlists provider interface are:

  • IPlaylistProvider. The root interface for the custom provider. It allows you to add any code that needs to be run while initializing or shutting down the provider.
  • IPlaylistRequestInfo. Enables a custom provider to access HTTP request attributes. These are exposed as server variables in the Internet Information Services (IIS) pipeline. This interface also allows a way for a custom provider to write some data to the provider in the form of a string.
  • IPlaylistInfo. Defines a playlist skeleton. It contains a collection of playlist entries in the form of IPlaylistEntryInfoCollection.
  • IPlaylistEntryInfo. Represents individual entries in a playlist. This contains properties such as Title, CanSeek, etc.
  • IPlaylistEntryInfoCollection. Allows a custom provider to traverse a list of playlist entries in the form of IPlaylistEntry info objects.
  • IPlaylistFileInfo (optional). Contains file information when the playlist is stored in a file and allows a method to access the file stream. This is useful as the IIS pipeline already has this information and the custom provider need not duplicate the functionality. IPlaylistFileInfo is useful if you are planning to write a file-based provider. It enables you to use file information from the IIS pipeline and get access to the file contents without having to implement the logic in the provider to open files, etc.

All but IPlaylistFileInfo are mandatory interfaces that must be implemented by a custom provider.

Sample code

The code sample in this section shows how to add an advertisment in front of the requested URL. This sample serves as a example tutorial for writing a custom provider (thus, it contains hard-coded strings). It is not supported and confers no rights.

using System;
using Microsoft.Web.Media.Playlist.Provider;
using System.Runtime.InteropServices;

namespace Microsoft.Web.Management.Media.Playlist.ProviderSample
{
public class PlaylistEntryInfo : IPlaylistEntryInfo
{
public PlaylistEntryInfo(string name, bool canSeekOrSkip)
{
_name = name;
_canSeekOrSkip = canSeekOrSkip;
}

ENTRY_TYPE IPlaylistEntryInfo.EntryType
{
get
{
return ENTRY_TYPE.EntryTypePhysicalFile;
}
}

string IPlaylistEntryInfo.Uri
{
get
{
return PlaylistProvider.MediaDirectory + _name;
}
}

Object IPlaylistEntryInfo.GetProperty(PLAYLIST_ENTRY_PROPERTY_TYPE propertyName)
{
switch (propertyName)
{
case PLAYLIST_ENTRY_PROPERTY_TYPE.PlaylistEntryProperty_CanSeek:
case PLAYLIST_ENTRY_PROPERTY_TYPE.PlaylistEntryProperty_CanSkipBackward:
case PLAYLIST_ENTRY_PROPERTY_TYPE.PlaylistEntryProperty_CanSkipForward:
return _canSeekOrSkip;
default:
return null;
}
}

private string _name;
private bool _canSeekOrSkip;
}

public class PlaylistInfo : IPlaylistInfo, IPlaylistEntryInfoCollection
{
public PlaylistInfo(string adname, string filename)
{
_entries = new IPlaylistEntryInfo[2];
_entries[0] = new PlaylistEntryInfo(adname, false);
_entries[1] = new PlaylistEntryInfo(filename, true);
}

IPlaylistEntryInfoCollection IPlaylistInfo.Entries
{
get
{
return this;
}
}

uint IPlaylistEntryInfoCollection.Count
{
get
{
return 2;
}
}

IPlaylistEntryInfo IPlaylistEntryInfoCollection.this[uint index]
{
get
{
return _entries[index];
}
}

Object IPlaylistInfo.GetProperty(PLAYLIST_PROPERTY_TYPE propertyName)
{
if (propertyName == PLAYLIST_PROPERTY_TYPE.PlaylistProperty_Title)
{
return "Wrapper Playlist";
}
return null;
}

void IPlaylistInfo.EndRequestStatus(uint urlEntryId, uint status, int completionStatus, ulong bytesSent)
{
// No processing for EndRequest
}

private IPlaylistEntryInfo[] _entries;
}

[Guid("D5178953-96A0-4ebd-B511-024897DA2C09")]
[ProgId("SamplePlaylistProvider.ProviderSample")]
[ComVisible(true)]
public class PlaylistProvider : IPlaylistProvider
{
IPlaylistInfo IPlaylistProvider.GetPlaylistInfo(IPlaylistRequestInfo requestInfo)
{
String path = requestInfo.Path;
String name = path.Substring(path.LastIndexOf('/') + 1);
name = name.Substring(0, name.LastIndexOf(".")) + FileExtension;
return new PlaylistInfo(Advertisement + FileExtension, name);
}

void IPlaylistProvider.Initialize()
{
//Load defaults for this provider... from config/xml etc
MediaDirectory = @"C:\Test\Media\";
Advertisement = "advertisement";
FileExtension = ".flv";
}

void IPlaylistProvider.Shutdown() { }

public static String MediaDirectory;
public static String Advertisement;
public static String FileExtension;
}
}

Building a custom provider

Building a .NET-based provider

Building a .NET-based provider is a two step process.

  1. Create a Type library (you can skip this step if you have access to released playlisthandler.dll)
    midl /I<Path to Web Playlists Include> playlistprovider.idl /tlb playlistprovider.tlb /win32
    midl /I<Path to Web Playlists Include> playlistprovider.idl /tlb playlistprovider.tlb /x64
    where <Path to Web Playlist Include> is the location where unzipped the Interface files too.
  2. Import Types into as assemblly
    1. Use the .tlb created in step 1
      tlbimp /out:<outputdirectory>\<outputprovidertypelib.tlb> /namespace:<Provider Namespace> <handler reference> 

      (E.g., tlbimp /out:E:\myprovider\playlistprovder.dll /namespace:Microsoft.Web.Media.Playlist.Provider E:\myprovider\playlistprovider.tlb )
    2. Use the released playlisthandler.dll
      tlbimp /out:<outputdirectory>\<outputproviderdll.dll> /namespace:<Provider Namespace> <path to playlist handler>\playlisthandler.dll

      (E.g., tlbimp /out:E:\myprovider\playlistprovder.dll /namespace:Microsoft.Web.Media.Playlist.Provider E:\myprovider\playlisthandler.dll )
  3. Compile the custom provider with reference to assembly created in step 2
    Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:TRACE 
    /reference:..\playlistprovder.dll
    /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll
    /debug:pdbonly /filealign:512 /optimize+
    /out:obj\Release\providersample.dll
    /target:library AssemblyInfo.cs PlaylistProvider.cs

Building a native provider (C++)

In the Resources section, you will find the link to Web Playlists interface files. After unzipping the file please follow the steps below:

  1. Include the header file for the appropriate platform in your source code
  2. Use your IDE (for example, Visual Studio) to build the provider dll.

Installing and running custom providers

Using the Playlists feature to add configuration entries for custom providers

1. In Internet Information Services (IIS) Manager, at the site level, click Playlists. (Ref: Figure 1)

Figure 1. IIS 7.0 Manager - Open the Playlists page

2. In the Actions pane, click Configure Providers. You will see the list of providers that are registered for the site. (Ref. Figure 2)

Figure 2. IIS 7.0 Manager - Open the Playlist providers page

3. In the Actions pane, click Add. (Ref. Figure 3)

Figure 3. Open the Add Playlist Provider dialog box

4. In the Add Playlist Provider dialog box, fill in the following details. Click OK when you are done. (Ref. Figure 4, 5)

  • Provider name. Enter a friendly name for the provider. It is only used to identify the provider in the Playlist providers page.
  • Description. Enter a description for the provider. You could use this field to briefly describe what the provider does. It is only used by the administrator to help identify the provider.
  • Program ID. Enter the COM ProgID that is used in the provider code. It is used to detect and load the provider at runtime.
  • File extension. Enter the file name extension that will be used for playlists that the provider will work with. The Playlists feature already handles Web playlists (file with .isx file name extensions). This field adds the handler mapping to the IIS config so that the Playlists feature can handle requests for this extension.
  • File-based handler (optional). As explained previously, this is an optional field. If your provider stores the playlist in a file, checking this option allows the IIS pipeline provide the needed file details and a stream to access file contents.
  • Bitness (64-bit systems only). Select whether the provider works as 32-bit through WOW layer, 64-bit, or both. The relevant configuration entries are added to the IIS config to handle the requests.

Figure 4. Add Playlist Provider dialog box

Figure 5. Bitness options for custom provider configuration

Manually registering custom providers

After you have added the relevant configuration entries by following the steps in the previous section, you must register the provider.

Registering a native custom provider

For 32-bit systems, do the following to register a native custom provider:

  1. Launch a command shell with administrator privileges (on the Start menu, right-click Command Prompt, and then click Run as administrator).
  2. Type the following command: %WINDIR%\system32\regsvr32.exe <providerdllname.dll> where providerdllname.dll is the provider dll.

For 64-bit systems, do the following to register a native custom provider:

  1. Launch a command shell with administrator privileges (on the Start menu, right-click Command Prompt, and then click Run as administrator).
  2. Type the following command:
    • For native 64 bit - %WINDIR%\system32\regsvr32.exe <providerdllname.dll> where providerdllname.dll is the provider dll.
    • For 32 bit supported through WOW layer - %WINDIR%\syswow64\regsvr32.exe <providerdllname.dll> where providerdllname.dll is the provider dll.

Registering a .NET-based custom provider

For 32-bit systems, do the following to register a .NET-based custom provider:

  1. Launch a command shell with administrator privileges (on the Start menu, right-click Command Prompt, and then click Run as administrator).
  2. In Command Prompt, navigate to the .NET Framework directory (for example, C:\Windows\Microsoft.NET\Framework\v2.0.50727).
  3. Type the following command: RegAsm.exe <providerdllname.dll> where providerdllname.dll is the provider dll.

For 64-bit systems, do the following to register a .NET-based custom provider:

  1. Launch a command shell with administrator privileges (on the Start menu, right-click Command Prompt, and then click Run as administrator).
  2. In Command Prompt, navigate to the .NET Framework directory (for example, C:\Windows\Microsoft.NET\Framework64\v2.0.50727).
  3. Type the following command: RegAsm.exe <providerdllname.dll> where providerdllname.dll is the provider dll.

For 64 bit systems, when you run as 32 bit through WOW layer, do the following to register a .NET-based custom provider

  1. Launch a command shell with administrator privileges (on the Start menu, right-click Command Prompt, and then click Run as administrator).
  2. In Command Prompt, navigate to the .NET Framework directory (for example, C:\Windows\Microsoft.NET\Framework\v2.0.50727).
  3. Type the following command: RegAsm.exe <providerdllname.dll> where providerdllname.dll is the provider dll.

Resources

Web Playlists Interface. Download this file and unzip the contents into a directory on your computer. The directory location will serve as your Web Playlists Include path.

Web Playlists Extensibility Support. View the Web Playlists Programming Reference and Programming Guide on the Microsoft Developer Network (MSDN).

Summary

In this walkthrough we learned how to write a custom provider and install it on the system. The writing portion should serve as a starting point; We recommend that you check out the Software Development Kit (SDK) for more detailed information.

The code sample in this document is just for tutorial purposes and to serve as an example. It is not supported and confers no rights.



Discuss in IIS Forums