jeeswg's Media Player Classic tutorial

Helpful script writing tricks and HowTo's
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

jeeswg's Media Player Classic tutorial

21 Dec 2017, 13:28

jeeswg's Media Player Classic Home Cinema tutorial

WM_COMMAND EXAMPLES

You can use PostMessage/SendMessage with WM_COMMAND to invoke various bits of functionality.

There is a list of WM_COMMAND codes lower down, obtained from here:
'View, Options...',
in the treeview: 'Player, Keys',
all the numbers in the ID column can be used with WM_COMMAND (0x111).

E.g. it says this about 'Play/Pause' (toggle):
Play/Pause Space 889
Thus you can use this code to invoke that:
SendMessage, 0x111, 889,,, ahk_class MediaPlayerClassicW ;WM_COMMAND := 0x111 ;Play/Pause (toggle)

Code: Select all

Media Player Classic: View, Options..., Player, Keys

Command	Key	ID
Quick Open File	Ctrl + Q	969
Open File/URL	Ctrl + O	800
Open DVD/BD	Ctrl + D	801
Open Device	Ctrl + V	802
Reopen File	Ctrl + E	976
Move to Recycle Bin		24044
Save a Copy		805
Save Image	Alt + I	806
Save Image (auto)	F5	807
Save thumbnails		808
Load Subtitles...	Ctrl + L	809
Save Subtitles...	Ctrl + S	810
Download Subtitles...	D	812
Upload Subtitles...	Ctrl + U	811
Close	Ctrl + C	804
Properties	Shift + F10	814
Exit	Alt + X	816
Play/Pause	Space	889
Play		887
Pause		888
Stop	.	890
Frame-step	Ctrl + Right Arrow	891
Frame-step back	Ctrl + Left Arrow	892
Go To	Ctrl + G	893
Increase Rate	Ctrl + Up Arrow	895
Decrease Rate	Ctrl + Down Arrow	894
Reset Rate	Ctrl + R	896
Audio Delay +10 ms	Add	905
Audio Delay -10 ms	Sub	906
Jump Forward (small)		900
Jump Backward (small)		899
Jump Forward (medium)	Right Arrow	902
Jump Backward (medium)	Left Arrow	901
Jump Forward (large)	Alt + Right Arrow	904
Jump Backward (large)	Alt + Left Arrow	903
Jump Forward (keyframe)	Shift + Right Arrow	898
Jump Backward (keyframe)	Shift + Left Arrow	897
Jump to Beginning	Home	996
Repeat Forever		33449
Repeat Mode: File		33450
Repeat Mode: Playlist		33451
Next	Page Down	922
Previous	Page Up	921
Next File	Ctrl + Page Down	920
Previous File	Ctrl + Page Up	919
Tuner scan	Shift + T	974
Quick add favorite	Shift + Q	975
Toggle Caption&Menu	Ctrl + 0	817
Toggle Seek Bar	Ctrl + 1	818
Toggle Controls	Ctrl + 2	819
Toggle Information	Ctrl + 3	820
Toggle Statistics	Ctrl + 4	821
Toggle Status	Ctrl + 5	822
Toggle Subresync Bar	Ctrl + 6	823
Toggle Playlist Bar	Ctrl + 7	824
Toggle Capture Bar	Ctrl + 8	825
Toggle Navigation Bar	Ctrl + 9	33415
Toggle Debug Shaders		826
View Minimal	1	827
View Compact	2	828
View Normal	3	829
Fullscreen	F11	830
Fullscreen (w/o res.change)	Alt + Enter	831
Zoom 50%	Alt + 1	832
Zoom 100%	Alt + 2	833
Zoom 200%	Alt + 3	834
Zoom Auto Fit	Alt + 4	968
Zoom Auto Fit (Larger Only)	Alt + 5	4900
Next AR Preset		859
VidFrm Half		835
VidFrm Normal		836
VidFrm Double		837
VidFrm Stretch		838
VidFrm Inside		839
VidFrm Zoom 1		841
VidFrm Zoom 2		842
VidFrm Outside		840
VidFrm Switch Zoom		843
Always On Top	Ctrl + A	884
PnS Reset	Num 5	861
PnS Inc Size	Num 9	862
PnS Inc Width	Num 6	864
PnS Inc Height	Num 8	866
PnS Dec Size	Num 1	863
PnS Dec Width	Num 4	865
PnS Dec Height	Num 2	867
PnS Center	Ctrl + Num 5	876
PnS Left	Ctrl + Num 4	868
PnS Right	Ctrl + Num 6	869
PnS Up	Ctrl + Num 8	870
PnS Down	Ctrl + Num 2	871
PnS Up/Left	Ctrl + Num 7	872
PnS Up/Right	Ctrl + Num 9	873
PnS Down/Left	Ctrl + Num 1	874
PnS Down/Right	Ctrl + Num 3	875
PnS Rotate X+	Alt + Num 8	877
PnS Rotate X-	Alt + Num 2	878
PnS Rotate Y+	Alt + Num 4	879
PnS Rotate Y-	Alt + Num 6	880
PnS Rotate Z+	Alt + Num 1	881
PnS Rotate Z-	Alt + Num 3	882
Volume Up	Up Arrow	907
Volume Down	Down Arrow	908
Volume Mute	Ctrl + M	909
Volume boost increase		970
Volume boost decrease		971
Volume boost Min		972
Volume boost Max		973
Toggle custom channel mapping		993
Toggle normalization		994
Toggle regain volume		995
Brightness increase		984
Brightness decrease		985
Contrast increase		986
Contrast decrease		987
Hue increase		988
Hue decrease		989
Saturation increase		990
Saturation decrease		991
Reset color settings		992
DVD Title Menu	Alt + T	923
DVD Root Menu	Alt + R	924
DVD Subtitle Menu		925
DVD Audio Menu		926
DVD Angle Menu		927
DVD Chapter Menu		928
DVD Menu Left	Alt + Left Arrow	929
DVD Menu Right	Alt + Right Arrow	930
DVD Menu Up	Alt + Up Arrow	931
DVD Menu Down	Alt + Down Arrow	932
DVD Menu Activate		933
DVD Menu Back		934
DVD Menu Leave		935
Boss key	B	944
Player Menu	App	949
Player Menu (full)		950
Filters Menu		951
Options	O	815
Next Audio Track	A	952
Prev Audio Track	Shift + A	953
Next Subtitle Track	S	954
Prev Subtitle Track	Shift + S	955
On/Off Subtitle	W	956
Reload Subtitles		2302
Next Angle (DVD)		961
Prev Angle (DVD)		962
Next Audio Track (DVD)		963
Prev Audio Track (DVD)		964
Next Subtitle Track (DVD)		965
Prev Subtitle Track (DVD)		966
On/Off Subtitle (DVD)		967
Tearing Test	Ctrl + T	32769
OSD: Display Current Time	Ctrl + I	32778
OSD: Show File Name	N	32777
Next Shader Preset		57382
Prev Shader Preset		57384
Toggle Direct3D fullscreen		32779
Goto Prev Subtitle	Y	32780
Goto Next Subtitle	U	32781
Shift Subtitle Left	Alt + Page Down	32782
Shift Subtitle Right	Alt + Page Up	32783
OSD: Display Renderer Statistics	Ctrl + J	32784
OSD: Reset Renderer Statistics	Ctrl + Alt + R	32785
VSync	V	33243
Enable Frame Time Correction		33265
Accurate VSync	Ctrl + Alt + V	33260
Decrease VSync Offset	Ctrl + Alt + Up Arrow	33246
Increase VSync Offset	Ctrl + Alt + Down Arrow	33247
Subtitle Delay -	F1	24000
Subtitle Delay +	F2	24001
After Playback: Do nothing		948
After Playback: Play next file in the folder		947
After Playback: Turn off the monitor		918
After Playback: Exit		912
After Playback: Stand By		913
After Playback: Hibernate		914
After Playback: Shutdown		915
After Playback: Log Off		916
After Playback: Lock		917
Toggle EDL window		846
EDL set In		847
EDL set Out		848
EDL new clip		849
EDL save		860

CODE EXAMPLES

Some Media Player Classic code:

Code: Select all

;note:
;SendMessage sends a message and waits for a reply (the reply is stored in ErrorLevel)
;PostMessage sends a message and doesn't wait for a reply
;it makes sense for the last call to be a PostMessage, and for any previous calls to be a SendMessage

;play/pause
SendMessage, 0x111, 887,,, ahk_class MediaPlayerClassicW ;WM_COMMAND := 0x111 ;Play
SendMessage, 0x111, 888,,, ahk_class MediaPlayerClassicW ;WM_COMMAND := 0x111 ;Pause
SendMessage, 0x111, 889,,, ahk_class MediaPlayerClassicW ;WM_COMMAND := 0x111 ;Play/Pause (toggle)

;get current file (2 methods)
WinGetTitle, vWinTitle, ahk_class MediaPlayerClassicW
RegRead, vPath, HKEY_CURRENT_USER, Software\MPC-HC\MPC-HC\Recent File List, File1

;list recent files
vOutput := ""
Loop 20
{
	RegRead, vPath, HKEY_CURRENT_USER, Software\MPC-HC\MPC-HC\Recent File List, % "File" A_Index
	if !(vPath = "")
		vOutput .= vPath "`r`n"
}
Clipboard := vOutput
MsgBox, % vOutput

;get/set Media Player Classic volume
SendMessage, 0x400, 0, 0, msctls_trackbar321, ahk_class MediaPlayerClassicW ;TBM_GETPOS := 0x400
vVolumeMPC := ErrorLevel
SendMessage, 0x422, 1, % vVolumeMPC, msctls_trackbar321, ahk_class MediaPlayerClassicW ;TBM_SETPOSNOTIFY := 0x422

;get mute status
SendMessage, 0x40A, 909,, ToolbarWindow321, ahk_class MediaPlayerClassicW ;TB_ISBUTTONCHECKED := 0x40A
vIsMute := ErrorLevel

;toggle mute status
PostMessage, 0x111, 909,,, ahk_class MediaPlayerClassicW ;WM_COMMAND := 0x111 ;Mute (toggle mute)

;toggle audio boost max/min
;note: equivalent to: Internal Filters, Audio Switcher, Boost
PostMessage, 0x111, 973,,, ahk_class MediaPlayerClassicW ;WM_COMMAND := 0x111 ;Volume boost Max
Sleep, 3000
PostMessage, 0x111, 972,,, ahk_class MediaPlayerClassicW ;WM_COMMAND := 0x111 ;Volume boost Min

;view, presets..., minimal/compact/normal
SendMessage, 0x111, 827,,, ahk_class MediaPlayerClassicW ;WM_COMMAND := 0x111 ;View Minimal
SendMessage, 0x111, 828,,, ahk_class MediaPlayerClassicW ;WM_COMMAND := 0x111 ;View Compact
SendMessage, 0x111, 829,,, ahk_class MediaPlayerClassicW ;WM_COMMAND := 0x111 ;View Normal

;get elapsed time/duration (assuming it's set to elapsed time, not remaining time)
ControlGetText, vTime, Static2, ahk_class MediaPlayerClassicW
vPos := InStr(vTime, "/")
vElapsed := SubStr(vTime, 1, vPos-2)
vDuration := SubStr(vTime, vPos+2)

;rotate 90 degrees (alt+numpad3)
SendMessage, 0x111, 882,,, ahk_class MediaPlayerClassicW ;WM_COMMAND := 0x111 ;PnS Rotate Z- (rotate 90 degrees)

;get/set window position, get/set fullscreen (full screen)
WinGetPos, vPosX, vPosY, vPosW, vPosH, ahk_class MediaPlayerClassicW
WinMove, ahk_class MediaPlayerClassicW,, % vPosX, % vPosY, % vPosW, % vPosH
SendMessage, 0x111, 830,,, ahk_class MediaPlayerClassicW ;WM_COMMAND := 0x111 ;Fullscreen
SendMessage, 0x111, 831,,, ahk_class MediaPlayerClassicW ;WM_COMMAND := 0x111 ;Fullscreen (w/o res.change)

;skip to point (if seek bar visible)
ControlGet, hCtl, Hwnd,, #327704, ahk_class MediaPlayerClassicW
ControlGetPos, vCtlX, vCtlY, vCtlW, vCtlH,, % "ahk_id " hCtl
vPosY := 5
vRatioX := 5 / 10
vCtlPos := Format("X{} Y{}", Round(vCtlW*vRatioX), vPosY)
ControlClick, % vCtlPos, % "ahk_id " hCtl

;(generic code that can be used on windows generally)
;set Media Player Classic 'on top' on/off
WinSet, AlwaysOnTop, On, ahk_class MediaPlayerClassicW
WinSet, AlwaysOnTop, Off, ahk_class MediaPlayerClassicW

;(generic code that can be used on windows generally)
;get/set minimised/maximised status (minimized/maximized)
WinMinimize, ahk_class MediaPlayerClassicW
WinMaximize, ahk_class MediaPlayerClassicW
WinRestore, ahk_class MediaPlayerClassicW
WinGet, vWinMinMax, MinMax, ahk_class MediaPlayerClassicW ;-1/0/1 min/neither/max

GET/SET PLAYBACK RATE

Code: Select all

#IfWinActive ahk_class MediaPlayerClassicW
q:: ;media player classic - set playback rate to 200%
WinGet, hWnd, ID, ahk_class MediaPlayerClassicW
SendMessage, 0x111, 896,,, % "ahk_id " hWnd ;WM_COMMAND := 0x111 ;Reset Rate
Loop 10
	SendMessage, 0x111, 895,,, % "ahk_id " hWnd ;WM_COMMAND := 0x111 ;Increase Rate
return

w:: ;media player classic - set playback rate to 100%
PostMessage, 0x111, 896,,, ahk_class MediaPlayerClassicW ;WM_COMMAND := 0x111 ;Reset Rate
return

e:: ;media player classic - set playback rate to 50%
WinGet, hWnd, ID, ahk_class MediaPlayerClassicW
SendMessage, 0x111, 896,,, % "ahk_id " hWnd ;WM_COMMAND := 0x111 ;Reset Rate
Loop 5
	SendMessage, 0x111, 894,,, % "ahk_id " hWnd ;WM_COMMAND := 0x111 ;Decrease Rate
return

r:: ;media player classic - get playback rate
ControlGetText, vRate, Static5, ahk_class MediaPlayerClassicW
MsgBox, % vRate
return
#IfWinActive

OPTIONS

[to speed up while maintaining pitch (you may need an MPC update)]
Options, Playback, Output,
choose Audio Renderer, 10: Internal Audio Renderer
key: HKEY_CURRENT_USER\Software\MPC-HC\MPC-HC\Settings
value: AudioRendererType (REG_SZ)

[to record recent files to the registry]
Options, Player, History,
tick Keep history of recently opened files
key: HKEY_CURRENT_USER\Software\MPC-HC\MPC-HC\Settings
value: RecentFilesNumber (REG_DWORD)

[to change the folder where snapshots are stored]
File, Save Image...
key: HKEY_CURRENT_USER\Software\MPC-HC\MPC-HC\Settings
value: SnapShotPath (REG_SZ)

LINKS

[download link for Media Player Classic + K-Lite Codec Pack Mega]
[one file, K-Lite_Codec_Pack_****_Mega.exe, contains everything, MPC *and* codecs]
Download K-Lite Codec Pack Mega
https://www.codecguide.com/download_k-lite_codec_pack_mega.htm

[a Media Player Classic API script I wrote, although generally I prefer to avoid using OnMessage]
winapi - media player classic - jump to point in video/audio programmatically - Stack Overflow
http://stackoverflow.com/questions/41310778/media-player-classic-jump-to-point-in-video-audio-programmatically

[a script request]
Any mpc-hc/_struct users can take a look at this api? - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=38700
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Tutorials (v1)”

Who is online

Users browsing this forum: No registered users and 40 guests