Partager via


IWMSPlaylistParser.WritePlaylist (Visual Basic .NET)

The WritePlaylist method writes the playlist files.

IWMSPlaylistParser.WritePlaylist(  pPlaylist As IXMLDOMDocument,
  pCallback As IWMSPlaylistParserCallback,
  qwContext As UInt64
)

Arguments

IXMLDOMDocumentIXMLDOMDocument Object (Visual Basic .NET) specifying the playlist file to write.

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

UInt64 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 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 is implemented by the plug-in and called by the server. The server calls the IWMSPlaylistParser.WritePlaylist method, if implemented, with a pointer to the result of the ReadPlaylist method call, which 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

The following is a sample user-defined playlist which 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.

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

    Dim NodeList As IXMLDOMNodeList
    Dim pBufAlloc As IWMSBufferAllocator
    Dim pINSSBuffer As INSSBuffer
    Dim strPls As String
    Dim strMedia As String
    Dim pBuf As IntPtr
    Dim i As Integer
    Dim j As Integer
    Dim Enc As Encoder = Encoding.Unicode.GetEncoder()
    Dim Bytes As Byte()
    Dim iBytes As Integer

    Try
        strPls = "!- DJ_FILE v1.0 -!" & vbCrLf

        NodeList = pPlaylist.getElementsByTagName("media")
        For i = 0 To (NodeList.length - 1)
            For j = 0 To (NodeList(i).attributes.length - 1)
                If NodeList(i).attributes(j).nodeName = "src" Then
                    strMedia = NodeList(i).attributes(j).nodeValue
                Else
                    strPls = strPls & "# " & _
                             NodeList(i).attributes(j).nodeName & _
                             "=" & Chr(34) & _
                             NodeList(i).attributes(j).nodeValue & _
                             Chr(34) & vbCrLf
                End If
            Next
            If Not strMedia = vbNullString Then
                strPls = strPls & strMedia & vbCrLf
            End If
        Next

        iBytes = Enc.GetByteCount(strPls.ToCharArray(), 0, _
                                  strPls.Length, False)
        Bytes = Array.CreateInstance(GetType(Byte), iBytes)
        iBytes = Enc.GetBytes(strPls.ToCharArray(), 0, _
                              strPls.Length, Bytes, 0, True)

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

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

        pCallback.OnWritePlaylist(S_OK, pINSSBuffer, qwContext)
    Catch e As Exception
        pCallback.OnWritePlaylist(E_FAIL, pINSSBuffer, 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)