Share via


Configuring a Publishing Point to Use a Wrapper Playlist

banner art

Previous Next

Configuring a Publishing Point to Use a Wrapper Playlist

To configure a publishing point to use a wrapper playlist, you must set the WrapperPath and EnableWrapperPath properties on the IWMSPublishingPoint interface. You can use a wrapper playlist to wrap advertisements and other messages around the content requested by a client. In a wrapper playlist, the content requested by the client is represented by the %RequestedURL% value. This is demonstrated in the following playlist created by the example code that follows.

<?wsx version = '1.0' ?>
<smil>
    <media src="c:\wmpub\wmroot\ad1.wmv"/>
    <media src="%RequestedURL%"/>
    <media src="c:\wmpub\wmroot\ad2.wmv"/>
</smil>

The following examples illustrate how to create the preceding wrapper playlist and specify that the existing broadcast publishing points use it.

Visual Basic .NET Example

Imports Microsoft.WindowsMediaServices.Interop
Imports interop_msxml

Private Sub ConfigurePPt()
  ' Declare variables.
  Dim Server As WMSServer
  Dim PubPoint As IWMSPublishingPoint
  Dim Playlist As IXMLDOMDocument
  Dim ElementSmil As IXMLDOMElement
  Dim ElementMedia As IXMLDOMElement
  Dim ProcInst As IXMLDOMNode
  Dim Root As IXMLDOMNode
  Dim Node As IXMLDOMNode

  Try
    ' Create a WMSServer object.
    Server = New WMSServer()

    ' Create a new playlist object.
    Playlist = Server.CreatePlaylist

    ' Create the processing instruction node.
    ProcInst = Playlist.createNode( _
                     DOMNodeType.NODE_PROCESSING_INSTRUCTION, _
                     "wsx", _
                     "")

    ' Add the processing instruction to the file structure.
    Playlist.appendChild(ProcInst)
    ProcInst.text = "version = '1.0'"

    ' Create the root node of the playlist.
    ElementSmil = Playlist.createElement("smil")

    ' Add the root node to the file structure.
    Root = Playlist.appendChild(ElementSmil)

    ' Create a media element for the playlist and assign
    ' a src attribute that identifies the first advertisement.
    ElementMedia = Playlist.createElement("media")
    ElementMedia.setAttribute("src", "c:\wmpub\wmroot\ad1.wmv")

    ' Add the media element to the root node.
    Node = Root.appendChild(ElementMedia)

    ' Create another media element for the playlist and
    ' assign a src attribute that points to the URL
    ' requested by the client.
    ElementMedia = Playlist.createElement("media")
    ElementMedia.setAttribute("src", "%RequestedURL%")

    ' Add the media element to the root node.
    Node = Root.appendChild(ElementMedia)

    ' Create a media element for the playlist and assign
    ' a src attribute that identifies the last advertisement.
    ElementMedia = Playlist.createElement("media")
    ElementMedia.setAttribute("src", "c:\wmpub\wmroot\ad2.wmv")

    ' Add the media element to the root node.
    Node = Root.appendChild(ElementMedia)

    ' Save the playlist.
    Playlist.save("c:\wmpub\wmroot\wrapper.wsx")
 
    ' Assign the playlist to each broadcast publishing point.
    For Each PubPoint In Server.PublishingPoints
      If WMS_PUBLISHING_POINT_TYPE.WMS_PUBLISHING_POINT_TYPE_BROADCAST = PubPoint.Type Then
        PubPoint.WrapperPath = "c:\wmpub\wmroot\wrapper.wsx"
        PubPoint.EnableWrapperPath = True
      End If
    Next

  Catch Err As Exception
    ' TODO: Exception handler goes here.

  Finally
    ' TODO: Clean-up code goes here.

  End Try

End Sub

C# Example

using Microsoft.WindowsMediaServices.Interop;
using interop_msxml;

// Declare the playlist, element, node, and publishing
// point variables.
IXMLDOMDocument   playlist;
IXMLDOMElement    element_smil, element_media;
IXMLDOMNode       proc_inst, root, node;
    
try
{
  // Create new server and playlist objects.
  WMSServer server = new WMSServer();
  playlist = (IXMLDOMDocument)server.CreatePlaylist();
    
  // Create the processing instruction node.
  proc_inst = playlist.createNode(
                           DOMNodeType.NODE_PROCESSING_INSTRUCTION,
                           "wsx",
                           "");
    
  // Add the processing instruction to the playlist.
  playlist.appendChild(proc_inst);
  proc_inst.text = "version = 1.0";
    
  // Create and add the root node of the playlist.
  element_smil = playlist.createElement("smil");
  root = playlist.appendChild(element_smil);
    
  // Create a media element and assign a src attribute
  // that identifies the first advertisement.
  element_media = playlist.createElement("media");
  element_media.setAttribute("src", "c:\\wmpub\\wmroot\\ad1.wmv");
  node = root.appendChild(element_media);
    
  // Create another media element for the playlist and
  // assign a src attribute that points to the URL
  // requested by the client.
  element_media = playlist.createElement("media");
  element_media.setAttribute("src", "%RequestedURL%");
  node = root.appendChild(element_media);
    
  // Create a media element for the playlist and assign a src 
  // attribute that identifies the last advertisement.
  element_media = playlist.createElement("media");
  element_media.setAttribute("src", "c:\\wmpub\\wmroot\\ad2.wmv");
  node = root.appendChild(element_media);
    
  // Save the playlist.
  playlist.save("c:\\wmpub\\wmroot\\wrapper.wsx");

  // Assign the playlist to each broadcast publishing point.
  foreach (IWMSPublishingPoint pubpoint in server.PublishingPoints)
  {
    if (pubpoint.Type == WMS_PUBLISHING_POINT_TYPE.WMS_PUBLISHING_POINT_TYPE_BROADCAST)
    {
      pubpoint.WrapperPath = "c:\\wmpub\\wmroot\\wrapper.wsx";
      pubpoint.EnableWrapperPath = true;
    }
  }
}

catch(Exception)
{
  // TODO: Exception handler goes here.
}

finally
{
  // TODO: Clean-up code goes here.
}

C++ Example

// Include header files.
#include <windows.h>
#include "wmsserver.h"
#include <atlbase.h>    // Includes CComBSTR and CComVariant.

// Declare variables and interfaces.
IXMLDOMDocument       *pPlaylist;
IXMLDOMElement        *pElement_Smil;
IXMLDOMElement        *pElement_Media;
IXMLDOMNode           *pProc_Inst, *pRoot, *pNode;
IXMLDOMNode           *pNodeNew;
IWMSPublishingPoints  *pPubPoints;
IWMSPublishingPoint   *pPubPoint;
IWMSServer            *pServer;
CComBSTR               bstrName, bstrNamespaceURI;
CComBSTR               bstrVersion, bstrWrapperPath;
CComVariant            varPath, varURL;
VARIANT_BOOL           bEnable;
long                   lPubPointsCt;
int                    i;
HRESULT                hr;
    
// Initialize the COM library and retrieve a pointer
// to an IWMSServer interface.
hr = CoInitialize(NULL);
if (FAILED(hr)) goto EXIT;

hr = CoCreateInstance(CLSID_WMSServer,
          NULL,
          CLSCTX_ALL,
          IID_IWMSServer,
          (void **)&pServer);
if (FAILED(hr)) goto EXIT;

// Create the playlist object.
hr = pServer->CreatePlaylist(&pPlaylist);
if (FAILED(hr)) goto EXIT;

// Create the processing instruction node.
bstrName  = "wsx";
bstrNamespaceURI = "";
      
hr = pPlaylist->createNode(
                  (CComVariant)NODE_PROCESSING_INSTRUCTION,
                  bstrName,
                  bstrNamespaceURI,
                  &pProc_Inst);
if (FAILED(hr)) goto EXIT;

// Add the processing instruction to the file structure.
hr = pPlaylist->appendChild(pProc_Inst, &pNodeNew);
if (FAILED(hr)) goto EXIT;

bstrVersion = "version = 1.0";
hr = pProc_Inst->put_text(bstrVersion);
if (FAILED(hr)) goto EXIT;

// Create and add the root node of the playlist.
bstrName = "smil";
hr = pPlaylist->createElement(bstrName, &pElement_Smil);
if (FAILED(hr)) goto EXIT;

hr = pPlaylist->appendChild(pElement_Smil, &pRoot);
if (FAILED(hr)) goto EXIT;

// Create a media element and add a src attribute.
bstrName = "media";
hr = pPlaylist->createElement(bstrName, &pElement_Media);
if (FAILED(hr)) goto EXIT;

bstrName = "src";
varPath = "c:\\wmput\\wmroot\\ad1.wmv";
hr = pElement_Media->setAttribute(bstrName, varPath);
if (FAILED(hr)) goto EXIT;

// Add the media element to the root node.
hr = pRoot->appendChild(pElement_Media, &pNode);
if (FAILED(hr)) goto EXIT;

// Create another media element for the playlist and
// assign a source attribute that points to the URL
// requested by the client.
bstrName = "media";
hr = pPlaylist->createElement(bstrName, &pElement_Media);
if (FAILED(hr)) goto EXIT;

bstrName = "src";
varURL = "%RequestedURL%";
hr = pElement_Media->setAttribute(bstrName, varURL);
if (FAILED(hr)) goto EXIT;

// Add the media element to the root node.
hr = pRoot->appendChild(pElement_Media, &pNode);
if (FAILED(hr)) goto EXIT;

// Create a media element for the playlist and assign
// a src attribute that identifies the last advertisement.
bstrName = "media";
hr = pPlaylist->createElement(bstrName, &pElement_Media);
if (FAILED(hr)) goto EXIT;

bstrName = "src";
varPath = "c:\\wmpub\\wmroot\\ad2.wmv";
hr = pElement_Media->setAttribute(bstrName, varPath);
if (FAILED(hr)) goto EXIT;

// Add the media element to the root node.
hr = pRoot->appendChild(pElement_Media, &pNode);
if (FAILED(hr)) goto EXIT;

// Save the playlist.
varPath = "c:\\wmpub\\wmroot\\wrapper.wsx";
hr = pPlaylist->save(varPath);
if (FAILED(hr)) goto EXIT;

// Assign the playlist to each broadcast publishing point.
hr = pServer->get_PublishingPoints(&pPubPoints);
hr = pPubPoints->get_Count(&lPubPointsCt);
for (i=0; i<lPubPointsCt; i++)
{
  WMS_PUBLISHING_POINT_TYPE PPType;
  hr = pPubPoints->get_Item((CComVariant)i, &pPubPoint);
  if (FAILED(hr)) goto EXIT;
  hr = pPubPoint->get_Type(&PPType);
  if (FAILED(hr)) goto EXIT;
  if (WMS_PUBLISHING_POINT_TYPE_BROADCAST != PPType) continue;
  bstrWrapperPath = "c:\\wmpub\\wmroot\\wrapper.wsx";
  hr = pPubPoint->put_WrapperPath(bstrWrapperPath);
  if (FAILED(hr)) goto EXIT;
  bEnable = true;
  hr = pPubPoint->get_EnableWrapperPath(&bEnable);
  if (FAILED(hr)) goto EXIT;
}

EXIT:
  // TODO: Release temporary COM objects and uninitialize COM.

See Also (General)

See Also (Visual Basic .NET)

See Also (C#)

See Also (C++)

Previous Next