다음을 통해 공유


IWMSPlaylistParser.ReadPlaylist (Visual Basic .NET)

The ReadPlaylist method is called by the server to retrieve a playlist from an INSSBufferINSSBuffer Object (Visual Basic .NET).

IWMSPlaylistParser.ReadPlaylist(  pBuffer As INSSBuffer,
  pPlaylist As IXMLDOMDocument,
  pCallback As IWMSPlaylistParserCallback,
  qwContext As UInt64
)

Arguments

INSSBuffer object specifying the buffer to read from.

IXMLDOMDocumentIXMLDOMDocument Object (Visual Basic .NET) to be used to store the interpreted playlist that can be understood by the server.

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

UInt64 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 (Visual Basic .NET) 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.

Public Sub ReadPlaylist( _
    ByVal pBuffer As INSSBuffer, _
    ByVal pPlaylist As interop_msxml.IXMLDOMDocument, _
    ByVal pCallback As IWMSPlaylistParserCallback, _
    ByVal qwContext As System.UInt64) _
    Implements IWMSPlaylistParser.ReadPlaylist

    Dim pNode As IXMLDOMNode
    Dim pSMIL As IXMLDOMElement
    Dim pElement As IXMLDOMElement
    Dim i As Integer
    Dim pdwLength As UInt32
    Dim pPlsBuf As IntPtr
    Dim strPlsBuf As String
    Dim strEntry As String
    Dim strPlsEntries As String()
    Dim colAttributeNames As New Collection()
    Dim colAttributeValues As New Collection()
    Dim Dec As Decoder = Encoding.UTF8.GetDecoder()
    Dim Chars As Char()
    Dim Bytes As Byte()
    Dim iChars As Integer

    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(pPlsBuf, pdwLength)

        Bytes = Array.CreateInstance(GetType(Byte), _
                                     Convert.ToInt32(pdwLength))
        Marshal.Copy(pPlsBuf, Bytes, 0, Convert.ToInt32(pdwLength))
        iChars = Dec.GetCharCount(Bytes, 0, Convert.ToInt32(pdwLength))
        Chars = Array.CreateInstance(GetType(Char), iChars)
        iChars = Dec.GetChars(Bytes, 0, Convert.ToInt32(pdwLength), _
                              Chars, 0)

        For i = 0 To Chars.Length - 1
            strPlsBuf = strPlsBuf & Chars(i)
        Next
        strPlsBuf = strPlsBuf.TrimStart()

        If strPlsBuf.StartsWith("!- DJ_FILE v") = False Then
            pCallback.OnReadPlaylist(E_FAIL, qwContext)
            Exit Sub
        End If

        strPlsEntries = strPlsBuf.Split(vbNewLine)

        For Each strEntry In strPlsEntries
            strEntry = strEntry.TrimStart()
            strEntry = strEntry.TrimEnd()
            If StrComp(strEntry, vbNullString) <> 0 Then
                If strEntry.StartsWith("#") = True Then
                    strEntry = strEntry.Remove(0, 1)
                    strEntry = strEntry.TrimStart()
                    strEntry = strEntry.Replace(Chr(34), "")
                    i = strEntry.IndexOf("=")

                    colAttributeNames.Add(strEntry.Substring(0, i))
                    colAttributeValues.Add(strEntry.Substring(i + 1, _
                                           strEntry.Length - i - 1))
                ElseIf strEntry.StartsWith("!-") = False Then
                    pElement = pPlaylist.createElement("media")
                    pElement.setAttribute("src", strEntry)

                    While colAttributeNames.Count > 0
                        pElement.setAttribute(colAttributeNames(1), _
                                              colAttributeValues(1))
                        colAttributeNames.Remove(1)
                        colAttributeValues.Remove(1)
                    End While

                    pSMIL.appendChild(pElement)
                End If
            End If
            strEntry = vbNullString
        Next

        pCallback.OnReadPlaylist(S_OK, qwContext)
    Catch e As Exception
        pCallback.OnReadPlaylist(E_FAIL, qwContext)
    End Try
End Sub

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 (Visual Basic .NET)