Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

Nature, to be commanded, must be obeyed. -- Francis Bacon


devel / comp.lang.tcl / Control a media player programmatically

SubjectAuthor
* Control a media player programmaticallyHelmut Giese
+* Control a media player programmaticallyScott Pitcher
|`* Control a media player programmaticallyHelmut Giese
| `- Control a media player programmaticallyRich
`* Control a media player programmaticallyet99
 `* Control a media player programmaticallyet99
  `* Control a media player programmaticallyHelmut Giese
   `- Control a media player programmaticallyet99

1
Control a media player programmatically

<36alki1jvi6b255stt28qqr5im10gjqnk5@4ax.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=12733&group=comp.lang.tcl#12733

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: hgiese@ratiosoft.com (Helmut Giese)
Newsgroups: comp.lang.tcl
Subject: Control a media player programmatically
Date: Tue, 07 Nov 2023 22:42:06 +0100
Organization: ratiosoft
Lines: 15
Message-ID: <36alki1jvi6b255stt28qqr5im10gjqnk5@4ax.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="8602d40008331755c16bb911156fd9c8";
logging-data="1275347"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/DbUuQuDWPxtqC6zlFpVrJ"
Cancel-Lock: sha1:FzAhXcFqaSQeHN1jmhj91N9C/jo=
X-Newsreader: Forte Free Agent 1.93/32.576 English (American)
 by: Helmut Giese - Tue, 7 Nov 2023 21:42 UTC

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

Re: Control a media player programmatically

<20231108095431.716bb46a@workshoppc.svpts>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=12734&group=comp.lang.tcl#12734

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: scotty@svptechnicalservices.com.au (Scott Pitcher)
Newsgroups: comp.lang.tcl
Subject: Re: Control a media player programmatically
Date: Wed, 8 Nov 2023 09:55:09 +1100
Organization: SVP TECHNICAL SERVICES
Lines: 33
Message-ID: <20231108095431.716bb46a@workshoppc.svpts>
References: <36alki1jvi6b255stt28qqr5im10gjqnk5@4ax.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="d0730184ec5df9ea6d1e8e625c51fe8f";
logging-data="1302227"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX187uKP9MyLmS/DB2dX8OWv66KoYGNSellk="
Cancel-Lock: sha1:96XMD5iTle0bsKLN3wtcmLRi1Fs=
X-Newsreader: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu)
 by: Scott Pitcher - Tue, 7 Nov 2023 22:55 UTC

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

--

Re: Control a media player programmatically

<uiehi1$1835r$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=12735&group=comp.lang.tcl#12735

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: et99@rocketship1.me (et99)
Newsgroups: comp.lang.tcl
Subject: Re: Control a media player programmatically
Date: Tue, 7 Nov 2023 15:34:25 -0800
Organization: A noiseless patient Spider
Lines: 64
Message-ID: <uiehi1$1835r$1@dont-email.me>
References: <36alki1jvi6b255stt28qqr5im10gjqnk5@4ax.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 7 Nov 2023 23:34:25 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="70bad4227ef0993a2e456b0855ca150d";
logging-data="1313979"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Vds0yLHeP5u9PZkL7Vy7W"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Cancel-Lock: sha1:c2hf7iWjIMVobHC2YucN+gI86xc=
In-Reply-To: <36alki1jvi6b255stt28qqr5im10gjqnk5@4ax.com>
Content-Language: en-US
 by: et99 - Tue, 7 Nov 2023 23:34 UTC

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/

Re: Control a media player programmatically

<uifvo5$1jm6j$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=12741&group=comp.lang.tcl#12741

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: et99@rocketship1.me (et99)
Newsgroups: comp.lang.tcl
Subject: Re: Control a media player programmatically
Date: Wed, 8 Nov 2023 04:42:45 -0800
Organization: A noiseless patient Spider
Lines: 76
Message-ID: <uifvo5$1jm6j$1@dont-email.me>
References: <36alki1jvi6b255stt28qqr5im10gjqnk5@4ax.com>
<uiehi1$1835r$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 8 Nov 2023 12:42:45 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="70bad4227ef0993a2e456b0855ca150d";
logging-data="1693907"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+d0PrLn49UiYYp3h63aD/8"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Cancel-Lock: sha1:gJJePgDzT/vkNSDm/628S7RcmYI=
Content-Language: en-US
In-Reply-To: <uiehi1$1835r$1@dont-email.me>
 by: et99 - Wed, 8 Nov 2023 12:42 UTC

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.

Re: Control a media player programmatically

<s3anki5mr2sbj0v6bms2sbm4ihdr77roqg@4ax.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=12742&group=comp.lang.tcl#12742

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: hgiese@ratiosoft.com (Helmut Giese)
Newsgroups: comp.lang.tcl
Subject: Re: Control a media player programmatically
Date: Wed, 08 Nov 2023 16:27:30 +0100
Organization: ratiosoft
Lines: 12
Message-ID: <s3anki5mr2sbj0v6bms2sbm4ihdr77roqg@4ax.com>
References: <36alki1jvi6b255stt28qqr5im10gjqnk5@4ax.com> <20231108095431.716bb46a@workshoppc.svpts>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="3314bde390af8eb97216d7f4376e79fb";
logging-data="1752675"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Fse1gpw6hTpMY5n/aVgAq"
Cancel-Lock: sha1:YKxklCqdJTCIUgup9RWF/PeqEFU=
X-Newsreader: Forte Free Agent 1.93/32.576 English (American)
 by: Helmut Giese - Wed, 8 Nov 2023 15:27 UTC

>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

Re: Control a media player programmatically

<g7anki52kvf9bhhsagdr9aj5isof3slpur@4ax.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=12743&group=comp.lang.tcl#12743

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: hgiese@ratiosoft.com (Helmut Giese)
Newsgroups: comp.lang.tcl
Subject: Re: Control a media player programmatically
Date: Wed, 08 Nov 2023 16:31:40 +0100
Organization: ratiosoft
Lines: 6
Message-ID: <g7anki52kvf9bhhsagdr9aj5isof3slpur@4ax.com>
References: <36alki1jvi6b255stt28qqr5im10gjqnk5@4ax.com> <uiehi1$1835r$1@dont-email.me> <uifvo5$1jm6j$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="3314bde390af8eb97216d7f4376e79fb";
logging-data="1752675"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18tOygvSbT4kkCjGEiKRXHa"
Cancel-Lock: sha1:hT3ps6aehIk2DB1N21JxcEy5ngo=
X-Newsreader: Forte Free Agent 1.93/32.576 English (American)
 by: Helmut Giese - Wed, 8 Nov 2023 15:31 UTC

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

Re: Control a media player programmatically

<uigg5o$1mqr5$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=12744&group=comp.lang.tcl#12744

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: Control a media player programmatically
Date: Wed, 8 Nov 2023 17:23:05 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <uigg5o$1mqr5$1@dont-email.me>
References: <36alki1jvi6b255stt28qqr5im10gjqnk5@4ax.com> <20231108095431.716bb46a@workshoppc.svpts> <s3anki5mr2sbj0v6bms2sbm4ihdr77roqg@4ax.com>
Injection-Date: Wed, 8 Nov 2023 17:23:05 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="f1dd542b1955a6b3d9279b8751d2c401";
logging-data="1796965"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19jmF2s/tI2z3g9Ywc3l5N8"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.117 (x86_64))
Cancel-Lock: sha1:A7J89u2PZFCrFcIwYXqW4a4YPJQ=
 by: Rich - Wed, 8 Nov 2023 17:23 UTC

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.

Re: Control a media player programmatically

<uiicge$25ee6$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=12769&group=comp.lang.tcl#12769

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: et99@rocketship1.me (et99)
Newsgroups: comp.lang.tcl
Subject: Re: Control a media player programmatically
Date: Thu, 9 Nov 2023 02:32:46 -0800
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <uiicge$25ee6$1@dont-email.me>
References: <36alki1jvi6b255stt28qqr5im10gjqnk5@4ax.com>
<uiehi1$1835r$1@dont-email.me> <uifvo5$1jm6j$1@dont-email.me>
<g7anki52kvf9bhhsagdr9aj5isof3slpur@4ax.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 9 Nov 2023 10:32:47 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="19d61fe8d49bc7fc00dc054854f24a9a";
logging-data="2275782"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/foQMeFJZ2+avdQuwY4jCe"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Cancel-Lock: sha1:QAl01AkTIihf8kPO09i0DaJGMz0=
In-Reply-To: <g7anki52kvf9bhhsagdr9aj5isof3slpur@4ax.com>
Content-Language: en-US
 by: et99 - Thu, 9 Nov 2023 10:32 UTC

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!

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor