Web Playlist for IIS 7.0 - Extending Web Playlists through custom providers

Published on April 16, 2008 by vsood

Updated on July 28, 2008 by vsood

Average Rating  Rate It (2)

RSS

Introduction

Web Playlists CTP2 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_PROPERTY_TYPE propertyName)
        {
            if (propertyName == PLAYLIST_PROPERTY_TYPE.PlaylistProperty_CanSeek ||
                propertyName == PLAYLIST_PROPERTY_TYPE.PlaylistProperty_CanSkipForward)
            {
                return _canSeekOrSkip;
            }
            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, true);
            _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;
        }

        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(".")) + ".wmv";
            return new PlaylistInfo(Advertisement, name);
        }

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

        void IPlaylistProvider.Shutdown() { }

        public static String MediaDirectory;
        public static String Advertisement;
       
    }

   
}

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 assemblely
    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 step2
    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 below you will find the link to Web Playlists CTP2 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 you IDE (e.g., 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 7.0 pipeline provide the needed file details and a stream to access file contents.
  • Bitness options (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 Playlist GoLive Interface - Download Now

Web Playlist CTP2 Interface - Download Now

Please download this file and unzip the contents into a directory on your machine. The location of your directory will serve as your Web Playlists Include path

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 released 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.

Related Content

Comments

  1. Submitted on Apr 22 2008 by
    winston1000
    I keep getting a 404 error whenever I access http://localhost/request/MediaFile>.wpl Module IIS Web Core Notification MapRequestHandler Handler PlaylistHandler-SamplePlaylistProvider.ProvderSample-wpl Error Code 0x80070002 Requested URL http://localhost:80/request/MediaFile>.wpl Physical Path H:\Projects\webPlaylist\MediaFile>.wpl Logon Method Anonymous Logon User Anonymous in H:\Projects\webPlaylist I have a file called advertisement.wmv and Initialize() has MediaDirectory = @"H:\Projects\webPlaylist\"; Advertisement = "advertisement.wmv"; any ideas?

You must Log In to comment.

Page view counter