AutoHotkey Community

It is currently May 27th, 2012, 12:48 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: October 4th, 2005, 2:28 pm 
Offline

Joined: October 2nd, 2005, 10:46 pm
Posts: 1
Here is some functions that attempts to make your media buttons a little more useful. My intention is to also map this code to a remote control. This is work in progress, i will update this thread over time.

Updated
Version 1.1:
* If you press play/pause button, and neither Winamp or MPC is running, Winamp is started.

Code:
; -----------------------------------------
; Play/Pause Button
;      If Winamp is playing a song, then pause Winamp
;      Else, if Media Player Classic is in focus, toggle Play/Pause in Media Player Classic
;      Else, if Winamp is paused, unpause Winamp
;      Else, if Winamp is stopped, play Winamp
; -----------------------------------------
Media_Play_Pause::
{
   WM_USER           = 0x0400
   WM_COMMAND        = 0x0111
   IPC_ISPLAYING     = 104
   WINAMP_BUTTON2    = 40045      ; Play button
   WINAMP_BUTTON3    = 40046      ; Pause button

   MPC_ID_PLAY_PLAYPAUSE = 157   ; Play/pause

   IfWinNotExist, Winamp
   {
      IfWinNotExist, Media Player Classic
      {
         Run, %ProgramFiles%\Winamp\Winamp.exe
         Return
      }
   }
   
   ;Is Winamp currently playing a song?
   SendMessage, WM_USER, 0, IPC_ISPLAYING,, ahk_class Winamp v1.x
   WinampStatus := ErrorLevel
   if (WinampStatus == 1) ; 1 = Winamp is playing
   {
      ;Pause Winamp
      SendMessage, WM_COMMAND, WINAMP_BUTTON3, WINAMP_BUTTON3,, ahk_class Winamp v1.x
      Return
   }
   
   ;Is MPC in focus?
   IfWinActive, ahk_class MediaPlayerClassicW
   {
      ;Toggle Play/Pause in MPC
      SendMessage, WM_COMMAND, MPC_ID_PLAY_PLAYPAUSE, MPC_ID_PLAY_PLAYPAUSE,, ahk_class MediaPlayerClassicW
      Return
   }

   ;Fixme: If MPC is _playing_ in the background = pause MPC (cant figure out how to get current state from MPC)
   ;......

   if (WinampStatus == 3 ) ; 3 = Winamp is paused
   {
      ;Play Winamp by pressing Pause button
      SendMessage, WM_COMMAND, WINAMP_BUTTON3, WINAMP_BUTTON3,, ahk_class Winamp v1.x
      Return
   }

   ;Play Winamp by pressing Play button
   SendMessage, WM_COMMAND, WINAMP_BUTTON2, WINAMP_BUTTON2,, ahk_class Winamp v1.x
   Return
}


; -----------------------------------------
; Volume Down Button
;      If Media Player Classic is focused, decrease volume there
;      Else, decrease volume in Winamp
; -----------------------------------------
Volume_Down::
{
   WM_COMMAND         = 0x0111
   
   MPC_ID_VOLUME_DOWN = 162
   WINAMP_VOLUMEDOWN  = 40059

   IfWinActive, ahk_class MediaPlayerClassicW
   {
      ;Decrease MPC volume
      SendMessage, WM_COMMAND, MPC_ID_VOLUME_DOWN, MPC_ID_VOLUME_DOWN,, ahk_class MediaPlayerClassicW
      Return
   }

   ;Decrease Winamp volume x2
   SendMessage, WM_COMMAND, WINAMP_VOLUMEDOWN, WINAMP_VOLUMEDOWN,, ahk_class Winamp v1.x
   SendMessage, WM_COMMAND, WINAMP_VOLUMEDOWN, WINAMP_VOLUMEDOWN,, ahk_class Winamp v1.x
   Return
}

; -----------------------------------------
; Volume Up Button
;      If Media Player Classic is focused, increase volume there
;      Else, increase volume in Winamp
; -----------------------------------------
Volume_Up::
{
   WM_COMMAND        = 0x0111
   
   MPC_ID_VOLUME_UP = 161
   WINAMP_VOLUMEUP = 40058

   IfWinActive, ahk_class MediaPlayerClassicW
   {
      ;Increase MPC volume
      SendMessage, WM_COMMAND, MPC_ID_VOLUME_UP, MPC_ID_VOLUME_UP,, ahk_class MediaPlayerClassicW
      Return
   }

   ;Increase Winamp volume x2
   SendMessage, WM_COMMAND, WINAMP_VOLUMEUP, WINAMP_VOLUMEUP,, ahk_class Winamp v1.x
   SendMessage, WM_COMMAND, WINAMP_VOLUMEUP, WINAMP_VOLUMEUP,, ahk_class Winamp v1.x
   Return
}

; -----------------------------------------
; Volume Mute Button
;      Some applications like MPC captures mute while focused, so we overwrite that behavior.
;      This makes the Mute button toggle master mute on/off
; -----------------------------------------
Volume_Mute::SoundSet, +1, MASTER, MUTE


Last edited by deadprez on October 11th, 2005, 2:29 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 5th, 2005, 1:35 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
It's good to have some automation for Media Player Classic posted, especially your use of SendMessage for greater reliability and the ability to control the window while it isn't active.

Thanks for posting it.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: August 9th, 2008, 9:40 pm 
Offline

Joined: March 27th, 2008, 7:46 pm
Posts: 129
Location: France
how grab the position and the name of file?
:for example to restaur him later


Report this post
Top
 Profile  
Reply with quote  
PostPosted: August 10th, 2008, 1:28 pm 
Offline

Joined: July 21st, 2006, 12:26 am
Posts: 223
soggos wrote:
how grab the position and the name of file?
:for example to restaur him later


Do you mean time?
Code:
ControlGetText, time, Static2, ahk_class MediaPlayerClassicW
msgbox %time%


and the name of the file can be extracted from the window title...

_________________
                                  [ profile | ahk.net | ahk.talk ]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 13th, 2008, 11:28 am 
Offline

Joined: March 27th, 2008, 7:46 pm
Posts: 129
Location: France
:): Thank K3tp :):

I have make that:
Code:

#Persistent

WinGetTitle, Title, ahk_class MediaPlayerClassicW
StringTrimRight, Title, Title, % StrLen( " - Media Player Classic" ) ; % ; ------
ControlGetText, OutputVar, Static2,%title%
StringLen, length, OutputVar

if length >14
{
StringRight, OutputVar, OutputVar, 8
StringRight, OutputVarS, OutputVar, 2
StringTrimRight, OutputVar, OutputVar, 3
StringRight, OutputVarM, OutputVar, 2
StringTrimRight, OutputVar, OutputVar, 3
StringRight, OutputVarH, OutputVar, 2



}
else
{
StringRight, OutputVar, OutputVar, 5
StringRight, OutputVarS, OutputVar, 2
StringTrimRight, OutputVar, OutputVar, 3
StringRight, OutputVarM, OutputVar, 2
OutputVarH = 0
}

OutputVarH2 := OutputVarH * 3600
OutputVarM2 := OutputVarM * 60
OutputVarS2 := OutputVarS * 1
TEMPS_TOTAL := OutputVarH2 +OutputVarM2 + OutputVarS2

;   MsgBox, 4096,, %OutputVarH%`n%OutputVarM%`n%OutputVarS%`n`n= %tempsseconde%

;MsgBox, 4096,, = %tempsseconde%

;tempsseconde := CONVERSIONenSECONDES(OutputVar)
gosub console

guicontrol ,,TEMPS_POSI1, 0
guicontrol ,,TEMPS_POSI2, %TEMPS_TOTAL%
  ;ControlGetPos, x, y, w, h, %Control%, ahk_id %id%
  ;ToolTip, = %tempsseconde%
;MsgBox, 4096,, = %tempsseconde%


SetTimer ,AFFICHE_TEMPS,500
return





; -------------------------------------------------------------------------------


CONSOLE:

Gui, Font, S8 Bold cGreen, Verdana
Gui, Add, Text, x6 y107 w130 h50 vNOMTITRE +Center, %title%
Gui, Font, S8 Bold cBlack, Verdana
Gui, Add, Text, x86 y7 w50 h20 , %TEMPS_TOTAL%
Gui, Font, S7 Norm cBlack, Verdana
Gui, Add, Button, x6 y47 w60 h20 gBOUCLE1, F1 &Debut
Gui, Add, Button, x6 y67 w80 h20 gBOUCLE2, F2 &Faire
Gui, Add, Edit, x86 y47 w50 h20 vTEMPS_POSI1 +Right,
Gui, Add, Edit, x86 y67 w50 h20 vTEMPS_POSI2 +Right,
Gui, Add, Edit, x86 y27 w50 h20 vTEMPS_POSIN,
Gui, Add, Button, x66 y47 w20 h20 gRAZBOUCLE1, 0
Gui, Add, Button, x6 y87 w130 h20 gRAZBOUCLE2, F3 &Stopper boucle


Gui, Show,  h168 w150,, %SelectedFileName%
Return



; -------------------------------------------------------------------------------

'::   ;4
F1::
BOUCLE1:
WinGetTitle, Title, ahk_class MediaPlayerClassicW
StringTrimRight, Title, Title, % StrLen( " - Media Player Classic" ) ; % ; ------
ControlGetText, OutputVar, Static2,%title%
TEMPS_POSI1 := CONVERSIONenSECONDES(OutputVar)

guicontrol ,,TEMPS_POSI1, %TEMPS_POSI1%

SplashTextOn, 100, 20,
SplashTextOff
return

; -------------------------------------------------------------------------------
è::   ;7
F2::
BOUCLE2:
WinGetTitle, Title, ahk_class MediaPlayerClassicW
StringTrimRight, Title, Title, % StrLen( " - Media Player Classic" ) ; % ; ------
ControlGetText, OutputVar, Static2,%title%
TEMPS_POSI2 := CONVERSIONenSECONDES(OutputVar)

guicontrol ,,TEMPS_POSI2, %TEMPS_POSI2%

SplashTextOn, 100, 20,
SplashTextOff
return



; -------------------------------------------------------------------------------


AFFICHE_TEMPS:

  ;ControlGetPos, x, y, w, h, %Control%, ahk_id %id%
  ;ToolTip, = %tempsseconde%
;MsgBox, 4096,, = %tempsseconde%
WinGetTitle, Title, ahk_class MediaPlayerClassicW
StringTrimRight, Title, Title, % StrLen( " - Media Player Classic" ) ; % ; ------
ControlGetText, OutputVar, Static2,%title%
tempsseconde := CONVERSIONenSECONDES(OutputVar)
guicontrol ,,TEMPS_POSIN, %tempsseconde%
guiControlGet ,TEMPS_POSI1
guiControlGet ,TEMPS_POSI2
az = 1 ; nombre de fois
if tempsseconde > %TEMPS_POSI2%
{
send à
Loop

{
   ControlSend , #327704, {Left %AZ%}, %title% ;my key for little back
ControlGetText, OutputVar, Static2,%title%
tempsseconde := CONVERSIONenSECONDES(OutputVar)
guicontrol ,,TEMPS_POSIN, %tempsseconde%
guiControlGet ,TEMPS_POSI1
guiControlGet ,TEMPS_POSI2
   if tempsseconde < %TEMPS_POSI1%
   {
   send à
   break
   }
}
}

return

; ------------------------------------------------------------------
RAZBOUCLE1:
guicontrol ,,TEMPS_POSI1, 0
return

ç::
F4::
F3::
RAZBOUCLE2:
guicontrol ,,TEMPS_POSI2, %TEMPS_TOTAL%
return

; -------------------------------------------------------------------------------

CONVERSIONenSECONDES(OutputVar) {

;MsgBox, 4096,, %OutputVar%`n
StringLen, length, OutputVar
;MsgBox, 4096,, %length%`n



;   MsgBox, 4096,, LONGUEUR=%length%`n %OutputVar%

if length >14
{
StringTrimRight, OutputVar, OutputVar, 11
StringRight, OutputVarS, OutputVar, 2
StringTrimRight, OutputVar, OutputVar, 3
StringRight, OutputVarM, OutputVar, 2
StringTrimRight, OutputVar, OutputVar, 3
StringRight, OutputVarH, OutputVar, 2
;   MsgBox, 4096,, %OutputVarH%`n%OutputVarM%`n%OutputVarS%`n
}
else
{
StringTrimRight, OutputVar, OutputVar, 8
StringRight, OutputVarS, OutputVar, 2
StringTrimRight, OutputVar, OutputVar, 3
StringRight, OutputVarM, OutputVar, 2
OutputVarH = 0
}

OutputVarH2 := OutputVarH * 3600
OutputVarM2 := OutputVarM * 60
OutputVarS2 := OutputVarS * 1
tempsseconde := OutputVarH2 +OutputVarM2 + OutputVarS2

;   MsgBox, 4096,, %OutputVarH%`n%OutputVarM%`n%OutputVarS%`n`n= %tempsseconde%

return %tempsseconde%
}
; -------------------------------------------------------------------------------


F5::
reload
return

F7::
ExitApp
return


GuiClose:
ExitApp

; -------------------------------------------------------------------------------


a little console for make a sample
define the begin and the end of the loop

but not clean
cause i send the <MPC hotkey for back
i prefer to send goto at MPC, but i dontt find how to make that!
do you no if it s possible?

:shock:


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: hughman and 3 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group