IWMSPlaylistParser.WritePlaylist (C#)

banner art

Previous Next

IWMSPlaylistParser.WritePlaylist (C#)

The WritePlaylist method writes the playlist files.

Syntax

  

Parameters

pPlaylist

IXMLDOMDocument object specifying the playlist file to write.

pCallback

IWMSPlaylistParserCallback object that is used by the plug-in to report to the server the result of the call to the WritePlaylist method.

qwContext

ulong containing a value defined by the server to identify which call to WritePlaylist the plug-in is responding to when it calls IWMSPlaylistParserCallback.OnWritePlaylist. You must pass this value back unaltered when you call OnWritePlaylist.

Return Values

This method does not return a value. To report an error, the plug-in can throw a COMException object to the server. If the plug-in uses the IWMSEventLog object to log error information, it is recommended that it throw NS_E_PLUGIN_ERROR_REPORTED (0xC00D157D). Typically, the server attempts to make plug-in error information available to the server object model, the Windows Event Viewer, and the troubleshooting list in the details pane of the Windows Media Services MMC. However, if the plug-in uses the IWMSEventLog object to send custom error information to the Windows Event Viewer, throwing NS_E_PLUGIN_ERROR_REPORTED stops the server from also logging to the event viewer. For more information about plug-in error information, see Identifying Plug-in Errors.

Remarks

This method is implemented by the plug-in and called by the server. The server calls the IWMSPlaylistParser.WritePlaylist method, sending it a pointer to the result of the ReadPlaylist method call. The result of the ReadPlaylist method call is an IXMLDOMDocument object specifying the playlist file that is to be written. This method need only be called if you want the file saved.

Example Code

The following is a sample user-defined playlist that can be written by the WritePlaylist method.

!- DJ_FILE v1.0 -! (this is a required tag)
media1.wmv

!- This is a comment -!
media2.wmv

!- Attributes apply to the next media element -!
# author=\"My Name\"
# description=\"My media file\"
# repeatCount=\"5\"
media3.wmv

This implementation of the WritePlaylist method will write the user-defined playlist.

void IWMSPlaylistParser.WritePlaylist(
    IXMLDOMDocument pPlaylist,
    IWMSPlaylistParserCallback pCallback,
    ulong qwContext)
{
    IXMLDOMNodeList NodeList;
    IWMSBufferAllocator pBufAlloc;
    INSSBuffer pINSSBuffer = null;
    string strPls;
    string strMedia = "";
    IntPtr pBuf;
    int i;
    int j;
    Encoder Enc = Encoding.Unicode.GetEncoder();
    byte[] Bytes;
    int iBytes;

    try
    {
        strPls = "!- DJ_FILE v1.0 -!\r\n";

        NodeList = pPlaylist.getElementsByTagName("media");
        for( i = 0; i < NodeList.length; i++ )
        {
            for( j = 0; j < NodeList[i].attributes.length; j++ )
            {
                if( NodeList[i].attributes[j].nodeName == "src" )
                    strMedia =
                          (string)NodeList[i].attributes[j].nodeValue;
                else
                    strPls = strPls + "# " +
                           NodeList[i].attributes[j].nodeName + "=\"" +
                           NodeList[i].attributes[j].nodeValue + "\"\r\n";
            }
            if( !strMedia.Equals("") )
                strPls = strPls + strMedia + "\r\n\r\n";
        }

        iBytes = Enc.GetByteCount(strPls.ToCharArray(), 0, strPls.Length,
                                  false);
        Bytes = (byte[])Array.CreateInstance(typeof(byte), iBytes);
        iBytes = Enc.GetBytes(strPls.ToCharArray(), 0, strPls.Length,
                              Bytes, 0, true);

        pBufAlloc = (IWMSBufferAllocator)m_ClassFactory;
        pBufAlloc.AllocateBuffer(Convert.ToUInt32(iBytes),
                                 out pINSSBuffer);
        pINSSBuffer.SetLength(Convert.ToUInt32(iBytes));
        pINSSBuffer.GetBuffer(out pBuf);

        Marshal.Copy(Bytes, 0, pBuf, iBytes);

        pCallback.OnWritePlaylist(S_OK, pINSSBuffer, qwContext);
    }
    catch
    {
        pCallback.OnWritePlaylist(E_FAIL, pINSSBuffer, qwContext);
    }
}

Requirements

Reference: Add a reference to Microsoft.WindowsMediaServices.

Namespace: Microsoft.WindowsMediaServices.Interop.

Assembly: Microsoft.WindowsMediaServices.dll.

Library: WMSServerTypeLib.dll.

Platform: Windows Server 2003, Enterprise Edition; Windows Server 2003, Datacenter Edition; Windows Server 2008.

See Also

Previous Next