Share via


Repeating a Broadcast

Broadcasts can be repeated easily any number of times through the use of playlist files. Playlists can direct a single media element or an entire sequence to repeat. You can programmatically modify playlist files by using the server object model and the XML Document Object Model (DOM). For more information, see XML DOM Interfaces (C++). The following examples illustrate how to create a playlist configured to repeat twice.

Visual Basic .NET Example

Imports Microsoft.WindowsMediaServices.Interop
Imports interop_msxml
Imports System.Runtime.InteropServices

' Declare variables.
Dim Server As WMSServer
Dim Playlist As IXMLDOMDocument
Dim ElementSmil As IXMLDOMElement
Dim ElementSeq As IXMLDOMElement
Dim ElementMedia As IXMLDOMElement
Dim NodeProcInst As IXMLDOMNode
Dim Root As IXMLDOMNode
Dim Seq 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
    ' to indicate the file type.
    NodeProcInst = Playlist.createNode(interop_msxml.DOMNodeType.NODE_PROCESSING_INSTRUCTION, _
                                       "wsx", _
                                       vbNullString)

    ' Add the file type version number to the node.
    NodeProcInst.text = "version=" & Chr(34) & "1.0" & Chr(34)

    ' Add the processing instruction to the file structure.
    Playlist.appendChild(NodeProcInst)

    ' 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 sequence element for the playlist.
    ElementSeq = Playlist.createElement("seq")

    ' Set the repeatCount attribute for the entire sequence.
    ElementSeq.setAttribute("repeatCount", "2")

    ' Set the id of the sequence.
    ElementSeq.setAttribute("id", "broadcast")

    ' Add the sequence node to the file structure.
    Seq = Root.appendChild(ElementSeq)

    ' Create a media element for the playlist.
    ElementMedia = Playlist.createElement("media")

    ' Set the src attribute for the media element.
    ElementMedia.setAttribute("src", "welcome1.asf")

    ' Add the media element under the sequence node in
    ' the file structure.
    Node = Seq.appendChild(ElementMedia)

    ' Create another media element for the playlist.
    ElementMedia = Playlist.createElement("media")

    ' Set the repeatCount attribute for this media element.
    ElementMedia.setAttribute("repeatCount", "5")

    ' Set the src attribute for the media element.
    ElementMedia.setAttribute("src", "welcome2.asf")

    ' Add the media element under the sequence node in
    ' the file structure.
    Node = Seq.appendChild(ElementMedia)

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

Catch errCom As COMException
    ' TODO: Handle COM exceptions.
Catch err As Exception
    ' TODO: Exception handler goes here.
Finally
    ' TODO: Clean-up code goes here.
End Try

C# Example

using Microsoft.WindowsMediaServices.Interop;
using interop_msxml;
using System.Runtime.InteropServices;

WMSServer Server;
IXMLDOMDocument Playlist;
IXMLDOMElement ElementSmil;
IXMLDOMElement ElementMedia;
IXMLDOMElement ElementSeq;
IXMLDOMNode NodeProcInst;
IXMLDOMNode Seq;
IXMLDOMNode Root;
IXMLDOMNode Node;

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

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

    // Create the processing instruction node
    // to indicate the file type.
    NodeProcInst = Playlist.createNode(interop_msxml.DOMNodeType.NODE_PROCESSING_INSTRUCTION,
                                       "wsx",
                                       null);

    // Add the file type version number to the node.
    NodeProcInst.text = "version=" + "\"" + "1.0" + "\"";

    // Add the processing instruction to the file structure.
    Playlist.appendChild(NodeProcInst);

    // 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 sequence element for the playlist.
    ElementSeq = Playlist.createElement("seq");

    // Set the repeatCount attribute for the entire sequence.
    ElementSeq.setAttribute("repeatCount", "2");

    // Set the id of the sequence.
    ElementSeq.setAttribute("id", "broadcast");

    // Add the sequence node to the file structure.
    Seq = Root.appendChild(ElementSeq);

    // Create a media element for the playlist.
    ElementMedia = Playlist.createElement("media");

    // Set the src attribute for the media element.
    ElementMedia.setAttribute("src", "welcome1.asf");

    // Add the media element under the sequence node in
   // the file structure.
    Node = Seq.appendChild(ElementMedia);

    // Create another media element for the playlist.
    ElementMedia = Playlist.createElement("media");

    // Set the repeatCount attribute for this media element.
    ElementMedia.setAttribute("repeatCount", "5");

    // Set the src attribute for the media element.
    ElementMedia.setAttribute("src", "welcome2.asf");

    // Add the media element under the sequence node in
    // the file structure.
    Node = Seq.appendChild(ElementMedia);

    // Save the playlist.
    Playlist.save("c:\\wmpub\\wmroot\\playlist.wsx");
}
catch (COMException comExc)
{
    // TODO: Handle COM exceptions.
}
catch (Exception exc)
{
    // TODO: Exception handler goes here.
}
finally
{
    // TODO: Clean-up code goes here.
}

C++ Example

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

// Declare variables and interfaces.
IWMSServer      *pServer;
IXMLDOMDocument *pPlaylist;
IXMLDOMElement  *pElementSmil;
IXMLDOMElement  *pElementSeq;
IXMLDOMElement  *pElementMedia;
IXMLDOMNode     *pNodeProcInst;
IXMLDOMNode     *pRoot;
IXMLDOMNode     *pSeq;
IXMLDOMNode     *pNode;

HRESULT         hr;
CComVariant     varFile;
CComBSTR        bstrName;
CComBSTR        bstrPath;

// 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;

// Create the processing instruction node
// to indicate the file type.
bstrName = "wsx";
varFile = NODE_PROCESSING_INSTRUCTION;
hr = pPlaylist->createNode(varFile, bstrName, NULL, &pNodeProcInst);
if (FAILED(hr)) goto EXIT;

// Add the file type version number to the node.
bstrName = "version=\"1.0\"";
hr = pNodeProcInst->put_text(bstrName);
if (FAILED(hr)) goto EXIT;

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

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

// Add the root node to the file structure.
hr = pPlaylist->appendChild(pElementSmil, &pRoot);
if (FAILED(hr)) goto EXIT;

// Create a sequence element for the playlist.
bstrName = "seq";
hr = pPlaylist->createElement(bstrName, &pElementSeq);
if (FAILED(hr)) goto EXIT;

// Set the repeatCount attribute for the entire sequence.
bstrName = "repeatCount";
varFile = "2";
hr = pElementSeq->setAttribute(bstrName, varFile);
if (FAILED(hr)) goto EXIT;

// Set the id of the sequence.
bstrName = "id";
varFile = "broadcast";
hr = pElementSeq->setAttribute(bstrName, varFile);
if (FAILED(hr)) goto EXIT;

// Add the sequence node to the file structure.
hr = pRoot->appendChild(pElementSeq, &pSeq);
if (FAILED(hr)) goto EXIT;

// Create a media element for the playlist.
bstrName = "media";
hr = pPlaylist->createElement(bstrName, &pElementMedia);
if (FAILED(hr)) goto EXIT;

// Set the src attribute for the media element.
bstrName = "src";
varFile = "welcome1.asf";
hr = pElementMedia->setAttribute(bstrName, varFile);
if (FAILED(hr)) goto EXIT;

// Add the media element under the sequence node in
// the file structure.
hr = pSeq->appendChild(pElementMedia, &pNode);
if (FAILED(hr)) goto EXIT;

// Create another media element for the playlist.
bstrName = "media";
hr = pPlaylist->createElement(bstrName, &pElementMedia);
if (FAILED(hr)) goto EXIT;

// Set the repeatCount attribute for this media element.
bstrName = "repeatCount";
varFile = "5”;
hr = pElementMedia->setAttribute(bstrName, varFile);
if (FAILED(hr)) goto EXIT;

// Set the src attribute for the media element.
bstrName = "src";
varFile = "welcome2.asf";
hr = pElementMedia->setAttribute(bstrName, varFile);
if (FAILED(hr)) goto EXIT;

// Add the media element under the sequence node in
// the file structure.
hr = pSeq->appendChild(pElementMedia, &pNode);
if (FAILED(hr)) goto EXIT;

// Save the playlist.
varFile = "file://c:\\wmpub\\wmroot\\playlist.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++)