Creating a Playlist
Previous | Next |
Creating a Playlist
You can create playlists in a text editor, or you can programmatically create and modify them by using the server object model and the XML DOM. The following examples illustrate how to create a playlist programmatically that uses a Windows Media file as a source.
Visual Basic .NET Example
Imports interop_msxml Imports Microsoft.WindowsMediaServices.Interop Private Sub Create() 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 new server and playlist objects. Server = New WMSServer() Playlist = Server.CreatePlaylist ' Create the processing instruction node. ProcInst = Playlist.createNode( _ DOMNodeType.NODE_PROCESSING_INSTRUCTION, _ "wsx", _ "") ' Add the processing instruction to the playlist. Playlist.appendChild(ProcInst) ProcInst.text = "version = '1.0'" ' Create and add the root node of the playlist. ElementSmil = Playlist.createElement("smil") Root = Playlist.appendChild(ElementSmil) ' Create a media element and assign a src attribute to it. ElementMedia = Playlist.createElement("media") ElementMedia.setAttribute("src", "c:\wmpub\wmroot\movie.wmv") ' Add the media element to the root node. Node = Root.appendChild(ElementMedia) ' Save the playlist. Playlist.save("c:\wmpub\wmroot\playlist_test_create.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; try { // Declare the playlist, element, and node variables. IXMLDOMDocument playlist; IXMLDOMElement element_smil, element_media; IXMLDOMNode proc_inst, root, node; // 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 to it. element_media = playlist.createElement("media"); element_media.setAttribute("src", "c:\\wmpub\\wmroot\\moview.wmv"); // Add the media element to the root node. node = root.appendChild(element_media); // Save the playlist. playlist.save("c:\\wmpub\\wmroot\\playlist_test.create.wsx"); } 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. 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 add a src attribute. bstrName = "media"; hr = pPlaylist->createElement(bstrName, &pElement_Media); if (FAILED(hr))goto EXIT; bstrName = "src"; varPath = "c:\\wmput\\wmroot\\moview.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\\playlist_test_create.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\movie.wmv"/> </smil>
See Also (General)
See Also (Visual Basic .NET)
- IWMSServer Object (Visual Basic .NET)
- IXMLDOMDocument Object (Visual Basic .NET)
- IXMLDOMElement Object (Visual Basic .NET)
- IXMLDOMNode Object (Visual Basic .NET)
See Also (C#)
- IWMSServer Object (C#)
- IXMLDOMDocument Object (C#)
- IXMLDOMElement Object (C#)
- IXMLDOMNode Object (C#)
See Also (C++)
Previous | Next |