Writing a Managed Web Playlist Provider

You must produce an interop assembly with managed interfaces before you can write a Web Playlist provider in managed code. This procedure is discussed in the document titled "Creating a Web Playlist Interop Assembly."

After you have created the interop assembly, you must create the implementation for a few interfaces. These interfaces are discussed below.

Interfaces

The interfaces included in the interop assembly are listed in the following table:

Interface

Description

IPlaylistProvider Interface

Serves as the root interface for a custom Playlist provider. This interface provides access to initialization and shutdown routines for a provider.

IPlaylistRequestInfo Interface

Enables custom providers to access HTTP request attributes. These attributes are exposed as server variables in the IIS 7 pipeline. String data may also be sent to the custom provider by using this interface.

IPlaylistInfo Interface

Defines an empty Playlist that contains a collection of Playlist entries in the form of an IPlaylistEntryInfoCollection Interface.

IPlaylistEntryInfo Interface

Represents individual entries in a Playlist.

IPlaylistEntryInfoCollection Interface

Allows a custom provider to traverse a list of Playlist entries in the form of IPlaylistEntryInfo Interface info objects.

IPlaylistFileInfo Interface

Provides access to the properties of file-based Playlists. Implementing this interface is not required, but it is recommended for file-based providers.

Each of these interfaces must be implemented before you can create a working provider, with the exception of IPlaylistFileInfo Interface. The IPlaylistFileInfo Interface interface is useful for file-based providers. It allows you to access file information from the IIS pipeline and gain access to the file contents without having to implement the logic in your provider to open files and perform file operations.

Example

The code sample below demonstrates how to add an advertisement to the beginning of a requested URL. This is an example of a managed Playlist provider:

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 PlaylistProviderSample : 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;

}

}

The PlaylistProviderSample class is the main class listed in this sample. Notice that it is marked with the ComVisible, ProgId, and Guid attributes. These attributes allow the provider to be registered and used by COM. The remainder of the classes in this sample are implementations of the other interfaces needed to support the PlaylistProviderSample class.

To build this sample, you will need the interop assembly created in the document, "Creating a Web Playlist Interop Assembly."

You can compile this sample by saving this code sample as "playlistprovidersample.cs" and then typing the following at an SDK command prompt:

csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:TRACE /reference:playlistprovider.dll /reference: c:\windows\microsoft.net\framework\v2.0.50727\system.dll /debugpdbonly /filealign:512 /optimize+ /out:obj\release\providersample.dll /target:library playlistprovidersample.cs

This command assumes that the interop assembly, playlistprovider.dll, is in the same directory as playlistprovidersample.cs.

See Also

Concepts

Creating a Web Playlist Interop Assembly

Installing a Custom Web Playlist Provider

Creating a Managed Playlist Provider