Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Smart Mediakeys - For Winamp & Media Player Classic


  • Please log in to reply
4 replies to this topic
deadprez
  • Members
  • 1 posts
  • Last active: Nov 01 2005 09:05 AM
  • Joined: 02 Oct 2005
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.

; -----------------------------------------
; 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


Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
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.

soggos
  • Members
  • 129 posts
  • Last active: Nov 30 2012 10:35 AM
  • Joined: 27 Mar 2008
how grab the position and the name of file?
:for example to restaur him later

danalec
  • Members
  • 225 posts
  • Last active: Oct 03 2014 05:31 PM
  • Joined: 20 Jul 2006

how grab the position and the name of file?
:for example to restaur him later


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

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

                                  [ profile ]


soggos
  • Members
  • 129 posts
  • Last active: Nov 30 2012 10:35 AM
  • Joined: 27 Mar 2008
:): Thank K3tp :):

I have make that:

#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 i prefer to send goto at MPC, but i dontt find how to make that!
do you no if it s possible?

:shock: