3

Summary: Looking for a way to get the current play time from VLC using VBA

I am looking for a way to launch VLC programmatically (Currently using a shell command from VBA/excel) and be able to programmatically read the current play time. I had a thought to extend with LUA and write the current time to a file in a loop. Unfortunately, it does not appear that LUA scripts can be automatically loaded by a command line parameter.

Is there a method to do this? some kind of VLC api? If so, how?

2 Answers2

1

I use the VLC HTTP requests (see https://wiki.videolan.org/VLC_HTTP_requests/).

I start vlc e.g. with following command:

"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" -I http --http-host=127.0.0.1 --http-port=9090 --http-password=abc "C:\path\to\your\audio.mp3"

In Word I use the following VBA-Code, which I assign to a shortcut key (e.g. F8)

Sub vlc_insert_time()
    Dim req As Object
    Set req = CreateObject("Microsoft.XMLHTTP")
    req.Open "GET", "http://127.0.0.1:9090/requests/status.xml", False
    req.SetRequestHeader "Content-Type", "application/json"
    req.SetRequestHeader "Accept", "application/json"
    req.SetRequestHeader "Authorization", "Basic " + EncodeBase64(StrConv("" + ":" + "abc", vbFromUnicode))
    req.Send
    resp = req.ResponseText
    Dim obj
    Set obj = CreateObject("MSXML2.DOMDocument.6.0")
    obj.LoadXML (resp)
    ts = o.SelectSingleNode("//root/time").text
    s = "[" + Format(ts / 3600 / 24, "hh\H:mm\M:ss\S") + "]" ' adapt this to your format
    Selection.TypeText s
End Sub

The function Base64Encode is borrowed from https://stackoverflow.com/a/169945/1659599. I repeat it here for convenience:

Function EncodeBase64(text As String) As String
    Dim arrData() As Byte
    arrData = StrConv(text, vbFromUnicode)

    Dim objXML As MSXML2.DOMDocument
    Dim objNode As MSXML2.IXMLDOMElement

    Set objXML = New MSXML2.DOMDocument
    Set objNode = objXML.createElement("b64")

    objNode.dataType = "bin.base64"
    objNode.nodeTypedValue = arrData
    EncodeBase64 = objNode.Text

    Set objNode = Nothing
    Set objXML = Nothing
End Function
wolfrevo
  • 6,651
  • 2
  • 26
  • 38
0

I’ve read before that there are command line switches that is built-in with the vlc package.