다음을 통해 공유


IWMSPlaylistParser.ReadPlaylist (C#)

The ReadPlaylist method is called by the server to retrieve a playlist from an INSSBufferINSSBuffer Object (C#).

void IWMSPlaylistParser.ReadPlaylist(
  INSSBuffer pBuffer,
  IXMLDOMDocument pPlaylist,
  IWMSPlaylistParserCallback pCallback,
  ulong qwContext
);

Arguments

INSSBuffer object specifying the buffer containing the playlist file.

IXMLDOMDocumentIXMLDOMDocument Object (C#) in which to store playlist can be understood by the server.

IWMSPlaylistParserCallbackIWMSPlaylistParserCallback Object (C#) that is used by the plug-in to report to the server the result of a call to the ReadPlaylist method.

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

Return Value

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 IWMSEventLogIWMSEventLog Object (C#) 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 retrieves a playlist from an INSSBuffer object, parses it, and populates an IXMLDOMDocument object. This method is implemented by the plug-in and called by the server.

Example

The following is a sample user-defined playlist that can be parsed by the ReadPlaylist 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 ReadPlaylist method will parse the user-defined playlist.

void IWMSPlaylistParser.ReadPlaylist(
    INSSBuffer pBuffer,
    IXMLDOMDocument pPlaylist,
    IWMSPlaylistParserCallback pCallback,
    ulong qwContext)
{
    IXMLDOMNode pNode;
    IXMLDOMElement pSMIL;
    IXMLDOMElement pElement;
    int i;
    uint pdwLength;
    IntPtr pPlsBuf;
    string strPlsBuf = "";
    string strEntry;
    string[] strPlsEntries;
    Queue colAttributes = new Queue();
    Decoder Dec = Encoding.UTF8.GetDecoder();
    char[] Chars;
    byte[] Bytes;
    int iChars;

    try
    {
        pNode = pPlaylist.createNode(
                   tagDOMNodeType.NODE_PROCESSING_INSTRUCTION, "wsx", "");
        pPlaylist.appendChild(pNode);
        pNode.text = "version='1.0'";

        pSMIL = pPlaylist.createElement("smil");
        pPlaylist.appendChild(pSMIL);

        pBuffer.GetBufferAndLength(out pPlsBuf, out pdwLength);

        Bytes = (byte[])Array.CreateInstance(typeof(byte),
                                             Convert.ToInt32(pdwLength));
        Marshal.Copy(pPlsBuf, Bytes, 0, Convert.ToInt32(pdwLength));
        iChars = Dec.GetCharCount(Bytes, 0, Convert.ToInt32(pdwLength));
        Chars = (char[])Array.CreateInstance(typeof(char), iChars);
        iChars = Dec.GetChars(Bytes, 0, Convert.ToInt32(pdwLength),
                              Chars, 0);

        for( i = 0; i < Chars.Length; i++ )
        {
            strPlsBuf = strPlsBuf + Chars[i];
        }
        strPlsBuf = strPlsBuf.TrimStart();

        if( !strPlsBuf.StartsWith("!- DJ_FILE v") )
        {
            pCallback.OnReadPlaylist((int)E_FAIL, qwContext);
            return;
        }

        strPlsEntries = strPlsBuf.Split('\n');

        foreach( string strLine in strPlsEntries )
        {
            strEntry = strLine;
            strEntry = strEntry.TrimStart();
            strEntry = strEntry.TrimEnd();
            if( !strEntry.Equals("") )
            {
                if( strEntry.StartsWith("#") )
                {
                    strEntry = strEntry.Remove(0, 1);
                    strEntry = strEntry.TrimStart();
                    strEntry = strEntry.Replace("\"", "");
                    i = strEntry.IndexOf("=");

                    colAttributes.Enqueue(strEntry.Substring(0, i));
                    colAttributes.Enqueue(strEntry.Substring(i + 1,
                                          strEntry.Length - i - 1));
                }
                else if( !strEntry.StartsWith("!-") )
                {
                    pElement = pPlaylist.createElement("media");
                    pElement.setAttribute("src", strEntry);

                    for( int j = 0; j < (colAttributes.Count * 2); j++ )
                    {
                        pElement.setAttribute(
                                         (string)colAttributes.Dequeue(),
                                         (string)colAttributes.Dequeue());
                    }

                    pSMIL.appendChild(pElement);
                }
            }
            strEntry = "";
        }

        pCallback.OnReadPlaylist(S_OK, qwContext);
    }
    catch
    {
        pCallback.OnReadPlaylist(E_FAIL, 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

Concepts

IWMSPlaylistParser Object (C#)