FuryCell

VLC automation over TCP

9 posts in this topic

#1 ·  Posted (edited)

I've been doing a lot of gaming lately and like to listen to music. Now a lot of other media players use up massive CPU cycles which kind of sucks when

your gaming on a 2ghz P4. So I turned to VLC. However,VLC seems to lack the ability to set global hotkeys so I could change tracks and such while in a full

screen game. I then decided to see if it had a com interface so i could script it. I had trouble,as others have had. Luckily,there is a solution to VLCs

lack of COM functionality. VLC provides an interface to its console commands over TCP. Here is a quick script to demonstrate it.

#NoTrayIcon
#include<File.au3>
#include <GUIConstants.au3>
#Region::: connect to vlc over tcp on localhost
TCPStartUp()
Global $Socket=TCPConnect("127.0.0.1",2150)
If $Socket=-1 Then
    MsgBox(0,"Error","Failed to connect to VLC over tcp proctol on localhost.Is it running and set to listen for console commands on port 2150?")
    Exit
EndIf
#EndRegion


#Region::: create and show GUI
$Form = GUICreate("VLC Test", 350, 58, -1, -1)
$ButtonPT = GUICtrlCreateButton("9", 8, 8, 105, 41, 0)
GUICtrlSetFont(-1, 14, 400, 0, "Webdings")
$ButtonS = GUICtrlCreateButton("<", 121, 8, 105, 41, 0)
GUICtrlSetFont(-1, 14, 400, 0, "Webdings")
$ButtonNT = GUICtrlCreateButton(":", 238, 8, 105, 41, 0)
GUICtrlSetFont(-1, 14, 400, 0, "Webdings")
GUISetState(@SW_SHOW)
#EndRegion

#Region::: msgloop
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $ButtonS
            TCPSend($Socket,"stop"&@CRLF) ;send stop command over tcp
        Case $ButtonNT
            TCPSend($Socket,"next"&@CRLF) ;send next command over tcp
        Case $ButtonPT
            TCPSend($Socket,"prev"&@CRLF) ;send prev command over tcp
        EndSwitch
WEnd
#EndRegion

For the example script to work you must set vlc to listen on 2150@localhost for console commands, and then click Add Interface>Console (See images for help)

Posted Image

Posted Image

Also,the small script above is just barely scratching the surface is what is possible. Here is a list of commands that can be invoked.

+----[ Remote control commands ]

|

| add XYZ . . . . . . . . . . add XYZ to playlist

| enqueue XYZ . . . . . . . queue XYZ to playlist

| playlist . . . show items currently in playlist

| play . . . . . . . . . . . . . . . . play stream

| stop . . . . . . . . . . . . . . . . stop stream

| next . . . . . . . . . . . . next playlist item

| prev . . . . . . . . . . previous playlist item

| goto . . . . . . . . . . . . goto item at index

| clear . . . . . . . . . . . clear the playlist

| status . . . . . . . . . current playlist status

| title [X] . . . . set/get title in current item

| title_n . . . . . . next title in current item

| title_p . . . . previous title in current item

| chapter [X] . . set/get chapter in current item

| chapter_n . . . . next chapter in current item

| chapter_p . . previous chapter in current item

|

| seek X . seek in seconds, for instance `seek 12'

| pause . . . . . . . . . . . . . . toggle pause

| fastforward . . . . . . . set to maximum rate

| rewind . . . . . . . . . . set to minimum rate

| faster . . . . . . . . faster playing of stream

| slower . . . . . . . . slower playing of stream

| normal . . . . . . . . normal playing of stream

| f [on|off] . . . . . . . . . . toggle fullscreen

| info . . . information about the current stream

| get_time . . seconds elapsed since stream's beginning

| is_playing . . 1 if a stream plays, 0 otherwise

| get_title . . . the title of the current stream

| get_length . . the length of the current stream

|

| volume [X] . . . . . . . . set/get audio volume

| volup [X] . . . . . raise audio volume X steps

| voldown [X] . . . . lower audio volume X steps

| adev [X] . . . . . . . . . set/get audio device

| achan [X]. . . . . . . . set/get audio channels

| atrack [X] . . . . . . . . . set/get audio track

| vtrack [X] . . . . . . . . . set/get video track

| vratio [X] . . . . . set/get video aspect ratio

| vcrop [X] . . . . . . . . . set/get video crop

| vzoom [X] . . . . . . . . . set/get video zoom

| strack [X] . . . . . . . set/get subtitles track

| menu [on|off|up|down|left|right|select] use menu

|

| help . . . . . . . . . . . . . this help message

| longhelp . . . . . . . . . a longer help message

| logout . . . . . exit (if in socket connection)

| quit . . . . . . . . . . . . . . . . . quit vlc

|

+----[ end of help ]

Hope this proves useful for some. muttley Edited by P5ych0Gigabyte

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

@P5ych0Gigabyte

This is realy great !!

I investigated the COM interface a while back, but didn't get far.

Thanks for this nice tutorial.

Regards

ptrex,

np. muttley I tried the com interface as well and it was frustrating as hell. This method seems to be a lot easier. :)

Edited by P5ych0Gigabyte

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites
:) Nice.

[center]It's a question of mind over matter, if I don't mind, it doesn't matter.[/center]

Share this post


Link to post
Share on other sites

#cs
+----[ Remote control commands ]
|
| add XYZ . . . . . . . . . . add XYZ to playlist
| enqueue XYZ . . . . . . . queue XYZ to playlist
| playlist . . . show items currently in playlist
| play . . . . . . . . . . . . . . . . play stream
| stop . . . . . . . . . . . . . . . . stop stream
| next . . . . . . . . . . . . next playlist item
| prev . . . . . . . . . . previous playlist item
| goto . . . . . . . . . . . . goto item at index
| clear . . . . . . . . . . . clear the playlist
| status . . . . . . . . . current playlist status
| title [X] . . . . set/get title in current item
| title_n . . . . . . next title in current item
| title_p . . . . previous title in current item
| chapter [X] . . set/get chapter in current item
| chapter_n . . . . next chapter in current item
| chapter_p . . previous chapter in current item
|
| seek X . seek in seconds, for instance `seek 12'
| pause . . . . . . . . . . . . . . toggle pause
| fastforward . . . . . . . set to maximum rate
| rewind . . . . . . . . . . set to minimum rate
| faster . . . . . . . . faster playing of stream
| slower . . . . . . . . slower playing of stream
| normal . . . . . . . . normal playing of stream
| f [on|off] . . . . . . . . . . toggle fullscreen
| info . . . information about the current stream
| get_time . . seconds elapsed since stream's beginning
| is_playing . . 1 if a stream plays, 0 otherwise
| get_title . . . the title of the current stream
| get_length . . the length of the current stream
|
| volume [X] . . . . . . . . set/get audio volume
| volup [X] . . . . . raise audio volume X steps
| voldown [X] . . . . lower audio volume X steps
| adev [X] . . . . . . . . . set/get audio device
| achan [X]. . . . . . . . set/get audio channels
| atrack [X] . . . . . . . . . set/get audio track
| vtrack [X] . . . . . . . . . set/get video track
| vratio [X] . . . . . set/get video aspect ratio
| vcrop [X] . . . . . . . . . set/get video crop


| vzoom [X] . . . . . . . . . set/get video zoom
| strack [X] . . . . . . . set/get subtitles track
| menu [on|off|up|down|left|right|select] use menu
|
| help . . . . . . . . . . . . . this help message
| longhelp . . . . . . . . . a longer help message
| logout . . . . . exit (if in socket connection)
| quit . . . . . . . . . . . . . . . . . quit vlc
|
+----[ end of help ]
#ce
#include "file.au3"

$vlcconfigfile = @AppDataDir&"\vlc\vlcrc"
$listen = " "

Opt("tcptimeout",500)

;Write correct settings to config file.
$vlcfile = FileOpen($vlcconfigfile,1)
_FileWriteToLine($vlcconfigfile,2529,"rc-host=127.0.0.1:2150",1);hostname and port
_FileWriteToLine($vlcconfigfile,2526,"rc-quiet=1",1);use quiet mode
FileClose($vlcfile)

;Run VLC Media Player and opens console
$vlcexe = Run(@ProgramFilesDir&"\VideoLAN\VLC\vlc.exe --extraintf rc")

Sleep(1500);Gives some time to start VLC

;Connect to VLC console
TCPStartup()
Global $vlcmp=TCPConnect("127.0.0.1",2150)
If $vlcmp=-1 Then
    MsgBox(0,"Error","Connecting error.")
    Exit
EndIf

;Main Loop
While 1
    $input = InputBox("VLC Console writer",$listen);Use above CMD list or "exit"
    If $input = "exit" Then
        OnAutoItExit()
    Else
        _SendData($input)
    EndIf
WEnd

Func _SendData($command)
    If $vlcmp = -1 Then;Checks if connected else gives error code see help file TCPConnect
        MsgBox(0,"",$vlcmp)
    Else
        TCPSend($vlcmp,$command&@CRLF);Send data to console
        $listen = TCPRecv($vlcmp,4096);Check if it gets someting back and shows it in inputbox
        Return $listen
    EndIf
EndFunc;=> _SendData()

Func OnAutoItExit()
;   TCPSend($vlcmp,"logout"&@CRLF)
;   TCPSend($vlcmp,"quit"&@CRLF)
    TCPShutdown()
    Exit
EndFunc;=> OnAutoItExit()

I made this out of it who can test it for me:P

i want to make it with hotkeys for in full screen apps like the TS said

Share this post


Link to post
Share on other sites

one question,

all of the controls is being done via localhost, is there a way to control VLC from outside the PC.

i have tried using Docklight, but i cant ever connect to VLC. is it a Windows thing?

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

@Techone Welcome to AutoIt forums! This thread is almost 6 years old, so most of the script would be broken (I didn't test) also there is an chance that VLC has changed/removed the functionality you are looking for.... I recommend to look for an other solution.

 

If you would still like to do that using this script then: Assuming that the script is working, you can replace 127.0.0.1 with the IP of the remote computer.

 

TD :)

Edited by TheDcoder
Welcome

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now