Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
You can use the server object model to create, retrieve, and modify a nested playlist. The following examples illustrate how to create one. For more information about nested playlists, see Nested Playlist Object.
Visual Basic .NET Example
Imports Microsoft.WindowsMediaServices.Interop
Imports interop_msxml
Private Sub CreateNested()
  ' Declare variables.
  Dim Server As WMSServer
  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 the WMSServer object.
    Server = New WMSServer()
    ' Create a new playlist.
    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 and add it to the playlist.
    ElementSmil = Playlist.createElement("smil")
    Root = Playlist.appendChild(ElementSmil)
    ' Create a media element and assign a src attribute
    ' that identifies another playlist.
    ElementMedia = Playlist.createElement("media")
    ElementMedia.setAttribute("src", "c:\wmpub\wmroot\playlist.wsx")
    ' Add the media element to the root node.
    Node = Root.appendChild(ElementMedia)
    ' Save the playlist.
    Playlist.save("c:\wmpub\wmroot\nestedplaylist.wsx")
  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, and node variables.
IXMLDOMDocument playlist;
IXMLDOMElement element_smil, element_media;
IXMLDOMNode proc_inst, root, node;
    
try
{
  // Create new server and playlist objects.
  WMSServer server = new WMSServerClass();
  playlist = (IXMLDOMDocument)server.CreatePlaylist();
    
  // Create the processing instruction node.
  proc_inst = playlist.createNode(DOMNodeType.
  NODE_PROCESSING_INSTRUCTION, "wsx", "");
    
  // Add the processing instruction to the file structure.
  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 another playlist.
  element_media = playlist.createElement("media");
  element_media.setAttribute("src", "c:\\wmpub\\wmroot\\playlist.wsx");
  node = root.appendChild(element_media);
    
  // Save the playlist.
  playlist.save("c:\\wmpub\\wmroot\\nestedplaylist.wsx");
}
catch
{
  // 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    *pElement_Smil, *pElement_Media;
IXMLDOMNode       *pProc_Inst, *pRoot, *pNode;
CComBSTR          bstrName, bstrNamespaceURI, bstrVersion;
CComVariant       varPath;
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, NULL);
if (FAILED(hr))goto EXIT; 
bstrVersion = "version = 1.0";
pProc_Inst->put_text(bstrVersion);
    
// 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 assign a src attribute
// that identifies another playlist.
bstrName = "media";
hr = pPlaylist->createElement(bstrName, &pElement_Media);
if (FAILED(hr))goto EXIT; 
bstrName = "src";
varPath = "c:\\wmpub\\wmroot\\playlist.wsx";
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\\nestedplaylist.wsx";
hr = pPlaylist->save(varPath);
if (FAILED(hr))goto EXIT; 
EXIT:
  // TODO: Release temporary objects and uninitialize COM.
The preceding examples create the following playlist.
<?wsx version = '1.0' ?>
<smil>
    <media src="c:\wmpub\wmroot\playlist.wsx"/>
</smil>
See Also (General)
See Also (Visual Basic .NET)
- IWMSServerIWMSServer Object (Visual Basic .NET) 
- IXMLDOMDocumentIXMLDOMDocument Object (Visual Basic .NET) 
- IXMLDOMElementIXMLDOMElement Object (Visual Basic .NET) 
- IXMLDOMNodeIXMLDOMNode Object (Visual Basic .NET) 
See Also (C#)
- IWMSServerIWMSServer Object (C#) 
- IXMLDOMDocumentIXMLDOMDocument Object (C#) 
- IXMLDOMElementIXMLDOMElement Object (C#) 
- IXMLDOMNodeIXMLDOMNode Object (C#) 
See Also (C++)
- IWMSServerIWMSServer Interface 
- IXMLDOMDocumentIXMLDOMDocument Interface 
- IXMLDOMElementIXMLDOMElement Interface 
- IXMLDOMNodeIXMLDOMNode Interface