• Control a media player programmatically

    From Helmut Giese@21:1/5 to All on Tue Nov 7 22:42:06 2023
    Hello out there,
    does anybody know of an example that controls a media player (any
    media player) programmatically? Not from a mobile phone or an IR
    device, but from a program running on the same machine.
    Preferably on Windows - but given the VM technology I think I could
    work with a Linux example, too.
    It needn't even be in Tcl (although it would of course be greatly
    preferred) - I think I could translate it from most languages to Tcl.
    I started with MPlayer (http://www.mplayerhq.hu). My first attempts
    with small snippets were encouraging but when it came to the real
    stuff MPlayer only stutttered and didn't advance (this was on
    Windows).

    Any tip or advice will be greatly appreciated
    Helmut

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Pitcher@21:1/5 to Helmut Giese on Wed Nov 8 09:55:09 2023
    On Tue, 07 Nov 2023 22:42:06 +0100
    Helmut Giese <hgiese@ratiosoft.com> wrote:

    Hello out there,
    does anybody know of an example that controls a media player (any
    media player) programmatically? Not from a mobile phone or an IR
    device, but from a program running on the same machine.
    Preferably on Windows - but given the VM technology I think I could
    work with a Linux example, too.
    It needn't even be in Tcl (although it would of course be greatly
    preferred) - I think I could translate it from most languages to Tcl.
    I started with MPlayer (http://www.mplayerhq.hu). My first attempts
    with small snippets were encouraging but when it came to the real
    stuff MPlayer only stutttered and didn't advance (this was on
    Windows).

    Any tip or advice will be greatly appreciated
    Helmut

    Hi Helmut,

    Did you have a look at mplayer's "-slave" mode?

    http://www.mplayerhq.hu/DOCS/tech/slave.txt

    Kind regards,
    Scott



    --

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From et99@21:1/5 to Helmut Giese on Tue Nov 7 15:34:25 2023
    On 11/7/2023 1:42 PM, Helmut Giese wrote:
    Hello out there,
    does anybody know of an example that controls a media player (any
    media player) programmatically? Not from a mobile phone or an IR
    device, but from a program running on the same machine.
    Preferably on Windows - but given the VM technology I think I could
    work with a Linux example, too.
    It needn't even be in Tcl (although it would of course be greatly
    preferred) - I think I could translate it from most languages to Tcl.
    I started with MPlayer (http://www.mplayerhq.hu). My first attempts
    with small snippets were encouraging but when it came to the real
    stuff MPlayer only stutttered and didn't advance (this was on
    Windows).

    Any tip or advice will be greatly appreciated
    Helmut

    I control the vlc media player from tcl. I use the portable version which you can get (for windows) at portableapps.com. Then I install it on my C drive using the portableapps installer. Then in the following folder,

    C:\PortableApps\VLCPortable\App\vlc\lua\http\requests

    There's a readme.txt file that shows how to send http requests for most of the commands such as play, pause, skipto, etc.

    Most of the commands are sent to the status.xml file, here's a tcl example where I seek +/- one second using the mousewheel.

    set ::playerhost localhost ;# can send to other machines on a lan also
    proc do_wheel1 {args} {
    set direction [lindex $args end]
    if { $direction > 0 } {
    http_geturl_auth "http://$::playerhost:8080/requests/status.xml?command=seek&val=-1s"
    } else {
    http_geturl_auth "http://$::playerhost:8080/requests/status.xml?command=seek&val=%2B1s"
    }
    }

    Here's one for pause:

    http_geturl_auth "http://$::playerhost:8080/requests/status.xml?command=pl_pause"


    There is some setup needed in the vlc program. The most recent versions needs a username and password, which I setup in the vlc program under (choose all settings)

    interfaces->main interfaces-> lua

    for a password of xyz and you send a blank username (I think that's required). Here's the code I use for the above http sends:

    package require base64
    proc http_geturl_auth {url {user {}} {pass xyz}} {
    return [geturl_auth $url $user $pass]
    }
    proc geturl_auth {url username password} {
    set auth "Basic [base64::encode $username:$password]"
    set headerl [list Authorization $auth]
    set tok [http::geturl $url -headers $headerl -timeout 200]
    return $tok
    }

    That should be enough to get you started if you want to use vlc from tcl/tk.

    This might be helpful also:

    https://wiki.videolan.org/Control_VLC_via_a_browser/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From et99@21:1/5 to All on Wed Nov 8 04:42:45 2023
    On 11/7/2023 3:34 PM, et99 wrote:
    On 11/7/2023 1:42 PM, Helmut Giese wrote:
    Hello out there,
    does anybody know of an example that controls a media player (any
    media player) programmatically? Not from a mobile phone or an IR
    device, but from a program running on the same machine.
    Preferably on Windows - but given the VM technology I think I could
    work with a Linux example, too.
    It needn't even be in Tcl (although it would of course be greatly
    preferred) - I think I could translate it from most languages to Tcl.
    I started with MPlayer (http://www.mplayerhq.hu). My first attempts
    with small snippets were encouraging but when it came to the real
    stuff MPlayer only stutttered and didn't advance (this was on
    Windows).

    Any tip or advice will be greatly appreciated
    Helmut

    I control the vlc media player from tcl. I use the portable version which you can get (for windows) at portableapps.com. Then I install it on my C drive using the portableapps installer. Then in the following folder,

    C:\PortableApps\VLCPortable\App\vlc\lua\http\requests

    There's a readme.txt file that shows how to send http requests for most of the commands such as play, pause, skipto, etc.

    Most of the commands are sent to the status.xml file, here's a tcl example where I seek +/- one second using the mousewheel.

    set ::playerhost localhost ;# can send to other machines on a lan also
    proc do_wheel1 {args} {
        set direction [lindex $args end]
        if { $direction > 0 } {
            http_geturl_auth "http://$::playerhost:8080/requests/status.xml?command=seek&val=-1s"
        } else {
            http_geturl_auth "http://$::playerhost:8080/requests/status.xml?command=seek&val=%2B1s"
        }
    }

    Here's one for pause:

    http_geturl_auth "http://$::playerhost:8080/requests/status.xml?command=pl_pause"


    There is some setup needed in the vlc program. The most recent versions needs a username and password, which I setup in the vlc program under (choose all settings)

    interfaces->main interfaces-> lua

    for a password of xyz and you send a blank username (I think that's required). Here's the code I use for the above http sends:

    package require base64
    proc http_geturl_auth {url {user {}} {pass xyz}} {
        return  [geturl_auth $url $user $pass]
    }
    proc geturl_auth {url username password} {
        set auth "Basic [base64::encode $username:$password]"
        set headerl [list Authorization $auth]
        set tok [http::geturl $url -headers $headerl -timeout 200]
        return $tok
    }

    That should be enough to get you started if you want to use vlc from tcl/tk.

    This might be helpful also:

    https://wiki.videolan.org/Control_VLC_via_a_browser/




    Forgot one more setting,

    https://wiki.videolan.org/Documentation:Modules/http_intf/#VLC_2.0.0_and_later

    need to check web and enter http in the text box below that as seen.

    And this can all work with the regular installed version, but I don't exactly know where all the directories are, but you should still be able to find the requests folder.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to Helmut Giese on Wed Nov 8 17:23:05 2023
    Helmut Giese <hgiese@ratiosoft.com> wrote:
    Hi Helmut,

    Did you have a look at mplayer's "-slave" mode?

    http://www.mplayerhq.hu/DOCS/tech/slave.txt

    Kind regards,
    Scott
    Hi Scott,
    yes, the experiences I mentioned were with using the -slave
    option.Thanks for your time
    Helmut

    One question, did you set the file descriptor linked to mplayer to non-blocking, and setup a read event to empty out the I/O buffer of
    mplayer's status updates it sends back (or run mplayer with the
    -really-quiet option to make it be really quiet)?

    Stuttering, as you mentioned in another post, might be the i/o buffers
    filling on the Tcl side, blocking the channel, which would eventually
    block mplayer too.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Helmut Giese@21:1/5 to All on Wed Nov 8 16:27:30 2023
    Hi Helmut,

    Did you have a look at mplayer's "-slave" mode?

    http://www.mplayerhq.hu/DOCS/tech/slave.txt

    Kind regards,
    Scott
    Hi Scott,
    yes, the experiences I mentioned were with using the -slave
    option.Thanks for your time
    Helmut

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Helmut Giese@21:1/5 to All on Wed Nov 8 16:31:40 2023
    Hi et99,
    thanks a lot for your many examples. This will surely give me a point
    to start from. I will only have to refresh my knowledge about using
    http and friends - but this should be manageable.
    Many thanks again and best regards
    Helmut

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From et99@21:1/5 to Helmut Giese on Thu Nov 9 02:32:46 2023
    On 11/8/2023 7:31 AM, Helmut Giese wrote:
    Hi et99,
    thanks a lot for your many examples. This will surely give me a point
    to start from. I will only have to refresh my knowledge about using
    http and friends - but this should be manageable.
    Many thanks again and best regards
    Helmut

    Vlc is an excellent player, I've been controlling it with tcl for over 10 years.

    Vlc never stutters for me, but sometimes a video is so highly compressed that I might decompress it a bit with handbrake so I can do instant skipping or video scrubbing.

    As far as http goes, there's really only 2 other functions you need, each using the handle returned on a call to geturl.

    http::data
    http::cleanup

    On each send of a url (with or without a command) to status.xml, it returns a string of xml. Nearly everything of importance is simply on a line of it's own as for example:

    <fullscreen>false</fullscreen>
    <aspectratio>default</aspectratio>
    <audiodelay>0</audiodelay>
    <time>2715</time>

    So, I just parse it with a couple of [split] calls into an array.

    proc dostat {} {
    catch {array unset ::status_array}
    if [catch {
    set handle [http_geturl_auth "http://$::playerhost:8080/requests/status.xml"]
    } result] {
    puts stderr "dostat: $result"
    return
    }
    set ::data [split [::http::data $handle] \n]

    foreach item $::data {
    set line [split $item "><"]
    if { [llength $line] >= 3 } {
    set ::status_array([lindex $line 1]) [lindex $line 2]
    }
    }
    ::http::cleanup $handle
    }


    Enjoy!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)