A Simple VLC Controller (Windows only)
Posted: Tue Aug 30, 2016 6:55 pm
Here's a small utility that uses the Windows API SendMessage() function to control the basic playback functionality of VLC.
Assumes that VLC is installed in the default x86 Program Files folder; please amend if different:
Might come in handy. 
Assumes that VLC is installed in the default x86 Program Files folder; please amend if different:
Code: Select all
;===========================================================
; Simple VLC Controller (through Windows API functions)
;
; tested on Windows 8.1 & 10 with PureBasic v5.50 (x64)
;
; by TI-994A - free to use, improve, share...
;
; 30th August 2016
;===========================================================
Global hVLC
Procedure findWindow(hWnd, lParam)
Protected winTitle.s{513}
GetWindowText_(hWnd, @winTitle, 512)
If FindString(winTitle, "vlc media player",
0, #PB_String_NoCase)
hVLC = hWnd
EndIf
ProcedureReturn #True
EndProcedure
Procedure findVLC()
EnumWindows_(@findWindow(), 0)
EndProcedure
Procedure nextVLC()
SendMessage_(hVLC, #WM_KEYDOWN, #VK_N, 0)
Delay(250)
SendMessage_(hVLC, #WM_KEYUP, #VK_N, 0)
EndProcedure
Procedure previousVLC()
SendMessage_(hVLC, #WM_KEYDOWN, #VK_P, 0)
Delay(250)
SendMessage_(hVLC, #WM_KEYUP, #VK_P, 0)
EndProcedure
Procedure pauseVLC()
SendMessage_(hVLC, #WM_KEYDOWN, #VK_SPACE, 0)
Delay(250)
SendMessage_(hVLC, #WM_KEYUP, #VK_SPACE, 0)
EndProcedure
Procedure stopVLC()
SendMessage_(hVLC, #WM_KEYDOWN, #VK_S, 0)
Delay(250)
SendMessage_(hVLC, #WM_KEYUP, #VK_S, 0)
EndProcedure
;multiple video files selectable (from the same folder)
fileName.s = OpenFileRequester("Select Media File:", "", "All files (*.*)|*.*", 0,
#PB_Requester_MultiSelection)
If fileName <> ""
filePath.s = GetPathPart(fileName)
While filename
multiFile$ + " " + GetFilePart(fileName)
fileName = NextSelectedFileName()
Wend
;assumes that VLC is installed in the default folder - please amend if different
RunProgram("C:\Program Files (x86)\VideoLAN\VLC\vlc.exe", multiFile$, filePath)
;allow VLC time to start
Delay(2000)
;find VLC window
findVLC()
If hVLC
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
window = OpenWindow(#PB_Any, #PB_Ignore, #PB_Ignore, 375, 50, "VLC Controller", wFlags)
vlcPause = ButtonGadget(#PB_Any, 10, 10, 100, 30, "PLAY/PAUSE")
vlcStop = ButtonGadget(#PB_Any, 120, 10, 75, 30, "STOP")
vlcNext = ButtonGadget(#PB_Any, 205, 10, 75, 30, "NEXT")
vlcPrev = ButtonGadget(#PB_Any, 290, 10, 75, 30, "PREVIOUS")
BindGadgetEvent(vlcStop, @stopVLC())
BindGadgetEvent(vlcPause, @pauseVLC())
BindGadgetEvent(vlcPrev, @previousVLC())
BindGadgetEvent(vlcNext, @nextVLC())
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
Else
MessageRequester("VLC Controller", "VLC window not found.")
EndIf
EndIf
