다음을 통해 공유


Modifying a Wrapper Playlist

Wrapper playlists can be edited programmatically from a locally stored file or while a client is actively streaming content. You can modify playlist files by using the server object model and the XML Document Object Model (DOM). The following examples illustrate how to modify a locally stored wrapper playlist.

Visual Basic .NET Example

Imports Microsoft.WindowsMediaServices.Interop
Imports interop_msxml

Private Sub ModifyWrapper()

  ' Declare variables.
  Dim Server As WMSServer
  Dim Playlist As IXMLDOMDocument
  Dim NodeList As IXMLDOMNodeList
  Dim ElementMedia As IXMLDOMElement
  Dim i As Integer

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

    ' Create a new playlist.
    Playlist = Server.CreatePlaylist

    ' Load an existing playlist.
    Playlist.load("c:\wmpub\wmroot\wrapper.wsx")

    ' Retrieve a list of all the media elements in the file.
    NodeList = Playlist.getElementsByTagName("media")

    ' Alter the path of each media element.
      For i = 0 To NodeList.length - 1

        ' Retrieve the next node in the list.
        ElementMedia = NodeList.item(i)

        ' Disable the ability to skip all content except
        ' the URL requested by the client.
        If Not ElementMedia.getAttribute("src") = "%RequestedURL%" Then
          ElementMedia.setAttribute("noSkip", "true")
        End If
      Next

    ' Save the playlist.
    Playlist.save("c:\wmpub\wmroot\wrapper.wsx")
    Exit Sub

    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 variables.
WMSServer Server;
IXMLDOMDocument Playlist;
IXMLDOMNodeList NodeList;
IXMLDOMElement ElementMedia;
int i;

try
{
  // Create the WMSServer object.
  Server = new WMSServerClass();

  // Create a new playlist.
  Playlist = Server.CreatePlaylist();

  // Load an existing playlist.
  Playlist.load("c:\\wmpub\\wmroot\\wrapper.wsx");

  // Retrieve a list of all the media elements in the file.
  NodeList = Playlist.getElementsByTagName("media");

  // Alter the path of each media element.
  for (i=0; i<NodeList.length; i++)
  {
    // Retrieve the next node in the list.
    ElementMedia = (IXMLDOMElement)NodeList[i];

    // Disable the ability to skip all content except
    // the URL requested by the client.
    if ((string)ElementMedia.getAttribute("src") != "%RequestedURL%")
    {
      ElementMedia.setAttribute("noSkip",  "true");
    }

    // Save the playlist.
    Playlist.save("c:\\wmpub\\wmroot\\wrapper.wsx");
  }
}

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

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

C++ Example

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

// Declare variables and interfaces.
IWMSServer      *pServer;
IXMLDOMDocument *pPlaylist;
IXMLDOMElement  *pElementMedia;
IXMLDOMNode     *pNode;
IXMLDOMNodeList *pNodeList;

HRESULT         hr;
VARIANT_BOOL    bVal;
CComVariant     varFile;
CComBSTR        bstrName;
long            lCount;

// Initialize the COM library and retrieve a pointer
// to an IWMSServer interface.
hr = CoInitialize(NULL);
hr = CoCreateInstance(CLSID_WMSServer,
                      NULL,
                      CLSCTX_ALL,
                      IID_IWMSServer,
                      (void **)&pServer);
if (FAILED(hr)) goto EXIT;

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

// Load an existing playlist.
varFile = "c:\\wmpub\\wmroot\\wrapper.wsx";
hr = pPlaylist->load(varFile, &bVal);
if (FAILED(hr)) goto EXIT;

// Retrieve a list of all the media elements in the file.
bstrName = "media";
hr = pPlaylist->getElementsByTagName(bstrName, &pNodeList);
if (FAILED(hr)) goto EXIT;

// Retrieve the total count of media elements.
hr = pNodeList->get_length(&lCount);
if (FAILED(hr)) goto EXIT;

// Alter the path of each media element.
for(long i = 0; i < lCount; i++)
{
    // Retrieve the next node in the list.
    hr = pNodeList->get_item(i, &pNode);
    if (FAILED(hr)) goto EXIT;

    // Query a pointer to the IXMLDOMElement interface.
    hr = pNode->QueryInterface(IID_IXMLDOMElement,
                              (void **)&pElementMedia);
    if (FAILED(hr)) goto EXIT;

    // Retrieve the src attribute for the element.
    bstrName = "src";
    hr = pElementMedia->getAttribute(bstrName, &varFile);
    if (FAILED(hr)) goto EXIT;

    // Disable the ability to skip all content except
    // the URL requested by the client.
    if(_wcsicmp(bstrName, L"%RequestedURL%") != 0)
    {
        // Add the noSkip attribute to the wrapped media.
        bstrName = "noSkip";
        varFile = "true";
        hr = pElementMedia->setAttribute(bstrName, varFile);
        if (FAILED(hr)) goto EXIT;
    }

    // Release the objects.
    pNode->Release();
    pElementMedia->Release();
}

// Save the playlist.
varFile = "c:\\wmpub\\wmroot\\wrapper.wsx";
hr = pPlaylist->save(varFile);
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++)