Sign in to follow this  
Followers 0
richardgray

How to remote control volume

2 posts in this topic

Hi I was wondering if someone can help me.

I want to be able to control the volume of a remote PC.

I want to be able to read the current volume level, then adjust the volume via a slider to set the remote volume level.

I have see the posts

for the adjusting the remote volume and

for the slider.

I may be able to link the two together but would really like to be able to have a starting value.

Thanks

Richard

Share this post


Link to post
Share on other sites



Wilt the help of using code supplied on the forums I have managed to get something to work, and I'm sure people will be able to tell me all I've done wrong :D

I used the simple TCP from matwachich, some of the audio from wraithdu (or I was going to if my server wasn't running XP) and the slider from elseware on the site, and I just cobbled them together.

This is the client side

#NoTrayIcon
;----------------------------------------------------------------------------
;
; AutoIt Version: 3.3.6.1
; Author:        Richard Gray
;
; Script Function: adjust Volume on remote PC
;Requires server function
;
;
;----------------------------------------------------------------------------
#include <GuiEdit.au3>
#include "TCPClient.au3"
TCPStartup()
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

; use this to resolve the host computer name to IP
Do
    $__CLIENTNAME = EnvGet ( "CLIENTNAME" )
$__CLIENTIP = TCPNameToIP($__CLIENTNAME)
;change this to be client host name
    If @error Then Exit
Until $__CLIENTNAME
#Region ### START Koda GUI section ### Form=

GUISetState(@SW_SHOW)
  $Form1 = GUICreate("Vol", 152, 48, 192, 114)
  $Slider1 = GUICtrlCreateSlider(0, 0, 150, 45)
  GUICtrlSetLimit($Slider1, 100, 0)
  GUICtrlSetData($Slider1, 50)
  $hSlider = GUICtrlGetHandle($Slider1)
  GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $tmp, $connTimer = TimerInit()
; Client creation, and callbacks functions assigning
Global $Client = _TCPClient_Create($__CLIENTIP, 53698, "motdepassedecryptagedesdonneessupersecret")
_TCPClient_SetCallbacks($Client, "_TCP_Recv")

; Main loop
While 1
    Switch GUIGetMsg()
        ; Befor exit, we destroy the client
        Case $GUI_EVENT_CLOSE
            _TCPClient_Destroy($Client)
            TCPShutdown()
            Exit
        ; ---
        ; Sending message, only if there is something in the Input
  Case $Slider1
   $sr = GUICtrlRead($Slider1)
   _TCPClient_Send($Client, $sr)
        ; ---
    EndSwitch
    ; ---
    ; If the client is disconnected, then we indefinitly try to connect once per second
    If Not _TCPClient_IsConnected($Client) Then
        If TimerDiff($connTimer) >= 1000 Then
            _TCPClient_Connect($Client)
            $connTimer = TimerInit()
        EndIf
    EndIf
    ; ---
    ; Processing function
    _TCPClient_Process()
WEnd

; Function called when a message is received from the server
Func _TCP_Recv($iClient, $Data)
    ; This line isn't very usefull in our example, but it would be usefull in a script containing many clients
    ; in order to (if all the client had the same callback function) know which client is concerned by the event
    If $iClient <> $Client Then Return
    ; ---
    ; If the message received is an identification request, then we identify ourself to the server
    ;If $Data = "#IDENTIFY#" Then
     ;   _TCPClient_Send($iClient, "#NAME#" & $__NickName)
     ;   Return
    ;EndIf
    ; ---
    ; Else, it's a simple chat message, so we display it in the Edit
    ;Local $read = GuiCtrlRead($Edit)
    ;GuiCtrlSetData($Edit, $read & $Data & @CRLF)
    ;_GUICtrlEdit_LineScroll($Edit, 0, _GUICtrlEdit_GetLineCount($Edit))
EndFunc

This is the server side

;----------------------------------------------------------------------------
;
; AutoIt Version: 3.3.6.1
; Author:        Richard Gray
;
; Script Function:
;   Server side for remote volume control
;
;----------------------------------------------------------------------------
#NoTrayIcon
#include "TCPServer.au3"
#include <_AudioEndpointVolume.au3>
#include <WindowsConstants.au3>
TCPStartup()

; Create the server
$_SERVERNAME=@ComputerName
$_SERVERIP=TCPNameToIP($_SERVERNAME)
_TCPServer_Create($_SERVERIP, 53698, 50, 1, "motdepassedecryptagedesdonneessupersecret")

; Assign it callback functions, that will be called when events occurs
_TCPServer_SetCallbacks("_TCP_New", "_TCP_Lost", "_TCP_Recv")

; Start the server
If Not _TCPServer_Start() Then Exit MsgBox(16, "Error", "Can not Start Server")

; Main loop, where the processing function is called
Global $run = 1
While $run
    _TCPServer_Process()
Wend

; Destroy the server and free ressources
_TCPServer_Destroy()
TCPShutdown()
; ##############################################################
; Function called when a new client connects
; it sends to the new connected client an identify request
Func _TCP_New($iSocket, $sIP)
;_TCPServer_Send($iSocket, "#IDENTIFY#")
;ConsoleWrite("New Client!" & @CRLF)
;$vol = _GetMasterVolumeLevelScalar()
;ConsoleWrite("Volume " & $vol & @CRLF)
;_TCPServer_Send($iSocket, $vol)
    ; ---
EndFunc

; it sends to other clients a disconnect notification
Func _TCP_Lost($iSocket, $sIP)
    ;Local $nick = _TCPServer_ClientPropertyGet($iSocket, 0)
    ;If $nick Then _TCPServer_Broadcast($nick & " Disconnected!")
    ; ---
    ;ConsoleWrite("Lost Client!" & @CRLF)
EndFunc
; Function called when a message is received from a client
Func _TCP_Recv($iSocket, $sIP, $Data)
    ; If the message is #CLOSE#:
    ;   We notify all clients that somebody requested closing the server
    ;   We set $run to 0
    ;If $Data = "#CLOSE#" Then
    ;    Local $nick = _TCPServer_ClientPropertyGet($iSocket, 0)
    ;    If $nick Then
    ;       _TCPServer_Broadcast($nick & " closed the server...")
    ;       $run = 0
    ;    EndIf
    ; ---
    ; If the message starts with #NAME#: It means that it's an identification
    ;   We extract the name from the received data (With StringTrimleft)
    ;   We assign it to the client's property N°0
    ;   We notify everybody that a new client is connected
    ;ElseIf StringLeft($Data, 6) = "#NAME#" Then
    ;    Local $nick = StringTrimLeft($Data, 6)
    ;    _TCPServer_ClientPropertySet($iSocket, 0, $nick)
    ;    _TCPServer_Broadcast($nick & " Connected!")
    ; ---
    ; Else, it's a simple message, so we broadcast it to every body, after adding
    ; to it as a prefix, the name of the client (contained in the client's property N°0)
    ;Else
        Local $nick = _TCPServer_ClientPropertyGet($iSocket, 0)
        ;If $nick Then _TCPServer_Broadcast("[" & $nick & "] " & $Data)
  ;ConsoleWrite("Volume " & $Data & @CRLF)
  SoundSetWaveVolume ($Data)
    ;EndIf
EndFunc

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
Sign in to follow this  
Followers 0