#AutoIt3Wrapper_UseX64=Y #include #include #include #include #include #include #include ; includes WinAPISysInternals.au3 HotKeySet("^!{RIGHT}", "_PlayNext") HotKeySet("^!{LEFT}", "_PlayPrevious") HotKeySet("^!{END}", "_Exit") HotKeySet("^!L", "_PlaylistDisplay") HotKeySet("^!{]}", "_SpeedUp") HotKeySet("^!{[}", "_SpeedDown") HotKeySet("^!{BS}", "_SpeedRevert") Global $aPos = WinGetPos("[Class:Shell_TrayWnd]") ; 0, 1032, 1920, 48 Global $iClientHeight = $aPos[1] Global $iClientWidth = $aPos[2] Global $aPlaylist, $sFolder _PlaylistCreate() ; libmpv-2.dll file can be downloaded at: https://github.com/shinchiro/mpv-winbuild-cmake/releases ; Download file name: mpv-dev-x86_64-20260307-git-f9190e5.7z $sDLL = @ScriptDir & "\libmpv-2.dll" Global $hMPV_DLL = DllOpen($sDLL) If $hMPV_DLL = -1 Then MsgBox(16, "Error", "libmpv-2.dll file cannot be loaded.") Exit EndIf Global $hUser32DLL = DllOpen("user32.dll") ; Create GUI to parent video Global $iVideoWidth = Int($iClientWidth/3*2) Global $iVideoHeight = Int($iVideoWidth*9/16) Global $hVideoGUI = GUICreate("AutoIt 4K MPV Player", $iVideoWidth, $iVideoHeight, -1, -1, $WS_OVERLAPPEDWINDOW) GUISetBkColor(0x000000, $hVideoGUI) ; Global variables for window metrics $aPos = WinGetPos($hVideoGUI) Global $iBorderWidth = ($aPos[2]-$iVideoWidth)/2 Global $iTitleHeight = $aPos[3]-$iVideoHeight-$iBorderWidth Global $iMaximizedTitleHeight ; To be defined in _PlayPause() ; Create video controls at the bottom of $hVideoGUI Global $iVCHeight = 55 Global $iVCLeft Global $iVCTop Global $iSliderLength2, $iProgBarWidth = 10 Global $hVCGui, $idSlider2, $idProgBar2, $idRepeatAB2, $idCurrentPos2, $idLength2, $idExit, $idPlay2 Global $idPrevious2, $idRepeat2, $idNext2, $idSpeaker2, $idUp2, $idDown2, $idVolume2, $idFullScreen Global $iRepeatCurrentFile, $iMute, $iVolume = 100, $iMediaLength, $iFullScreen, $iMaximized, $aPrePos _VCCreate() GUIRegisterMsg($WM_WINDOWPOSCHANGED, "WM_WINDOWPOSCHANGED") ; To sync movements of $hVideoGUI and $hVCGui Global $pHandle = DllCall($hMPV_DLL, "ptr:cdecl", "mpv_create")[0] If Not $pHandle Then Exit _mpv_set_options() DllCall($hMPV_DLL, "int:cdecl", "mpv_initialize", "ptr", $pHandle) ; Chagne $sKeepAspect to "no" if you want the video image not to keep aspect ratio Global $iAspect, $sKeepAspect = "yes" If $sKeepAspect = "yes" Then _mpv_set_property($pHandle, "keepaspect", "yes", "string") Else _mpv_set_property($pHandle, "keepaspect", "no", "string") EndIf _mpv_set_property($pHandle, "volume", $iVolume, "double") Global $iIndex = 1 Global $aMsg, $sMsg, $iPlayPrevious, $sIdle, $aMouse, $iHitTest Global $iDoubleclickTime = DllCall($hUser32DLL, 'uint', 'GetDoubleClickTime')[0], $iClickCount, $iTimer _PlayFile() While 1 $aMsg = GUIGetMsg(1) $sMsg = $aMsg[0] Switch $aMsg[1] Case $hVideoGUI Switch $sMsg Case $GUI_EVENT_CLOSE _PlayNext() Case $GUI_EVENT_MAXIMIZE $iMaximized = 1 If WinExists($hVCGui) Then _VCResize() Case $GUI_EVENT_RESTORE $iMaximized = 0 If WinExists($hVCGui) Then _VCResize() Case $GUI_EVENT_RESIZED If $iFullScreen+$iMaximized = 0 And $sKeepAspect = "yes" Then _VideoResize() EndIf Case $GUI_EVENT_PRIMARYDOWN $aMouse = MouseGetPos() $iHitTest = _SendMessage($hVideoGUI, $WM_NCHITTEST, 0, _WinAPI_MakeLong($aMouse[0], $aMouse[1])) If $iHitTest = 1 Then $iClickCount += 1 If $iClickCount = 1 Then $iTimer = TimerInit() EndIf EndSwitch Case $hVCGui Switch $sMsg Case $idDown2 _mpv_command($pHandle, "add", "ao-volume", "-5") $iVolume = _mpv_get_property($pHandle, "ao-volume", "double") GUICtrlSetTip($idDown2, $iVolume) GUICtrlSetTip($idUp2, $iVolume) Case $idUp2 _mpv_command($pHandle, "add", "ao-volume", "5") $iVolume = _mpv_get_property($pHandle, "ao-volume", "double") GUICtrlSetTip($idUp2, $iVolume) GUICtrlSetTip($idDown2, $iVolume) Case $idPlay2 _PlayPause() Case $idPrevious2 _PlayPrevious() Case $idNext2 _PlayNext() Case $idExit _Exit() Case $idSpeaker2 _mpv_command($pHandle, "cycle", "mute") If GUICtrlRead($idSpeaker2) = "🔊" Then GUICtrlSetData($idSpeaker2, "🔇") Else GUICtrlSetData($idSpeaker2, "🔊") EndIf Case $idRepeat2 If GUICtrlRead($idRepeat2) = "U" Then $iRepeatCurrentFile = 1 GUICtrlSetData($idRepeat2, "0") Else $iRepeatCurrentFile = 0 GUICtrlSetData($idRepeat2, "U") EndIf Case $idFullScreen _FullScreen() Case $idSlider2 _Slider() EndSwitch EndSwitch If $iClickCount > 0 Then Local $aPos1 = MouseGetPos() If $aPos1[0] > $aPos[0]+50 And $aPos1[0] < $aPos[0]+$aPos[2]-50 And $aPos1[1] > $aPos[1]+50 And $aPos1[1] < $aPos[1]+$aPos[3]-50 Then If $iClickCount >= 2 Then _FullScreen() $iClickCount = 0 ElseIf TimerDiff($iTimer) > $iDoubleclickTime Then _PlayPause() $iClickCount = 0 EndIf EndIf EndIf ; If $sIdle = "yes" then move to the next file $sIdle = _mpv_get_property($pHandle, "idle-active") If $sIdle = "yes" Then GUISetState(@SW_HIDE, $hVideoGUI) AdlibUnRegister("_VCShow") AdlibUnRegister("_Progress") If $iRepeatCurrentFile <> 1 Then If $iPlayPrevious = 0 Then $iIndex += 1 If $iIndex > $aPlaylist[0] Then $iIndex = 1 Else $iIndex -= 1 If $iIndex = 0 Then $iIndex = $aPlaylist[0] EndIf EndIf $iPlayPrevious = 0 _PlayFile() Sleep(100) EndIf Sleep(20) WEnd Func _Exit() ; Terminates the program (Click "🞭" in $hVCGui or pres Ctrl+Alt+End) _mpv_command($pHandle, "stop") DllCall($hMPV_DLL, "void:cdecl", "mpv_terminate_destroy", "ptr", $pHandle) DllClose($hMPV_DLL) DllClose($hUser32DLL) Exit EndFunc ; _Exit Func _FullScreen() ; Video in full screen mode on/off (Click ⇔/⇙ $hVCGui) HotKeySet("{F11}") AdlibUnRegister("_VCShow") WinSetTrans($hVCGui, "", 0) If $iFullScreen = 0 Then $iFullScreen = 1 GUICtrlSetData($idFullScreen, "⇙") GUISetStyle($WS_OVERLAPPEDWINDOW, -1, $hVideoGUI) Local $x, $y, $w, $h $x = -$iBorderWidth $y = 0 $w = @DesktopWidth+$iBorderWidth*2 $h = @DesktopHeight+$iBorderWidth GUISetStyle($WS_POPUP, -1, $hVideoGUI) WinMove($hVideoGUI, "", $x, $y, $w, $h) WinSetOnTop($hVideoGUI, "", 1) _VCResize() Else GUICtrlSetData($idFullScreen, "⇔") GUISetStyle($WS_OVERLAPPEDWINDOW-$WS_MINIMIZEBOX, -1, $hVideoGUI) WinSetOnTop($hVideoGUI, "", 0) $iFullScreen = 0 GUISetStyle($WS_OVERLAPPEDWINDOW, -1, $hVideoGUI) WinMove($hVideoGUI, "", $aPrePos[0], $aPrePos[1], $aPrePos[2], $aPrePos[3]) _VCResize() EndIf AdlibRegister("_VCShow") HotKeySet("{F11}", _FullScreen) EndFunc ; _FullScreen Func _GetVideoCardSpec() ; Get video card spec, to be used for setting hardware acceleration options Local $oWMIService = ObjGet("winmgmts:\\.\root\cimv2") Local $colItems = $oWMIService.ExecQuery("SELECT Name, AdapterRAM FROM Win32_VideoController") Local $hasExternalGPU = False Local $gpuName = "" If IsObj($colItems) Then For $oItem In $colItems $gpuName = $oItem.Name If StringInStr($gpuName, "NVIDIA") Or StringInStr($gpuName, "Radeon") Or StringInStr($gpuName, "RTX") Or StringInStr($gpuName, "GTX") Then ; Embedded GPU may require other method to check its availability $hasExternalGPU = True EndIf If $oItem.AdapterRAM >= 2147483648 Then ; Embedded GPU may show lower RAM size $hasExternalGPU = True EndIf Next EndIf If $hasExternalGPU Then Return "high" Else Return "low" EndIf EndFunc ; _GetVideoCardSpec Func _HotkeySet() ; Adlib function to set/unset {F11} and {ESC} hotkeys, 990ms ; Set or unset {F11} and {ESC} full screen hotkeys depending on visibility of video window Local $tPoint = _WinAPI_CreatePoint($aPos[0]+$aPos[2]/2, $aPos[1]+$aPos[3]/2) Local Static $iHotkeySet_Esc, $iHotkeySet_F11 If _WinAPI_WindowFromPoint($tPoint) = $hVideoGUI Then If $iHotkeySet_F11 = 0 Then HotKeySet("{F11}", _FullScreen) $iHotkeySet_F11 = 1 EndIf If $iFullScreen = 1 And $iHotkeySet_Esc = 0 Then HotKeySet("{ESC}", _FullScreen) $iHotkeySet_Esc = 1 ElseIf $iFullScreen = 0 And $iHotkeySet_Esc = 1 Then HotKeySet("{ESC}") $iHotkeySet_Esc = 0 EndIf Else If $iHotkeySet_F11 = 1 Then HotKeySet("{F11}") $iHotkeySet_F11 = 0 If $iHotkeySet_Esc = 1 Then HotKeySet("{ESC}") $iHotkeySet_Esc = 0 EndIf EndIf EndIf EndFunc ;==>_HotkeySet Func _PlayFile() ; Invoked by the main loop when the player is in idle state _mpv_set_property($pHandle, "speed", 1.0, "double") _mpv_command($pHandle, "loadfile", $sFolder & $aPlaylist[$iIndex]) Sleep(100) For $i = 1 To 20 ; Wait for a maximum of 200ms $iAspect = _mpv_get_property($pHandle, "video-params/aspect", "double") If $iAspect > 0 Then ExitLoop Sleep(50) Next If $iAspect > 0 Then ;~ If $sKeepAspect = "yes" Then ;~ _mpv_set_property($pHandle, "keepaspect", "yes", "string") ;~ Else ;~ _mpv_set_property($pHandle, "keepaspect", "no", "string") ;~ EndIf $iVideoWidth = _mpv_get_property($pHandle, "width", "double") $iVideoHeight = _mpv_get_property($pHandle, "height", "double") $iVideoWidth = Int($iClientWidth*2/3) $iVideoHeight = Int($iVideoWidth/$iAspect) If $iVideoHeight > $iClientHeight-$iTitleHeight Then $iVideoHeight = $iClientHeight-$iTitleHeight $iVideoWidth = Int($iVideoHeight*$iAspect) EndIf Local $x = ($iClientWidth-$iVideoWidth-$iBorderWidth*2)/2, $y = ($iClientHeight-$iVideoHeight-$iTitleHeight-$iBorderWidth)/2 Local $w = $iVideoWidth+$iBorderWidth*2, $h = $iVideoHeight+$iTitleHeight+$iBorderWidth WinMove($hVideoGUI, "", $x, $y, $w, $h) GUISetState(@SW_SHOW, $hVideoGUI) GUIDelete($hVCGui) _VCCreate() ; _VCResize() Else MsgBox(1, "Error", $aPlaylist[$iIndex] & @CRLF & "This file cannot be loaded.") _Exit() EndIf $iMediaLength = Int(_mpv_get_property($pHandle, "duration")) GUICtrlSetData($idLength2, _SecondsToTime($iMediaLength)) AdlibRegister("_VCShow") AdlibRegister("_Progress") AdlibRegister("_HotkeySet", 990) AdlibRegister("_VideoRefresh", 300000) WinSetTitle($hVideoGUI, "", "AutoIt 4K MPV Player - " & $aPlaylist[$iIndex]) EndFunc ; _PlayFile Func _PlaylistCreate() ; Create a playlist at the beginning of the program Local $sFileTypes = "*.mp4;*.wmv;*.avi;*.mkv;*.flv;*.webM" Local $sFiles, $sMsg, $iRet $sFiles = FileOpenDialog("Load one or more video files", "", "Video (" & $sFileTypes & ")", 7) If $sFiles = "" Then Exit If Not StringInStr($sFiles, "|") Then Local $iPos = StringInStr($sFiles, "\", 0, -1) $sFiles = StringLeft($sFiles, $iPos) & "|" & StringMid($sFiles, $iPos+1) EndIf $aPlaylist = StringSplit($sFiles, "|") ; Folder name|File 1|File 2... $sFolder = $aPlaylist[1] If StringRight($sFolder, 1) <> "\" Then $sFolder &= "\" $sFile = $sFolder & $aPlaylist[2] _ArrayDelete($aPlaylist, 1) $aPlaylist[0] = UBound($aPlaylist)-1 EndFunc ; _PlaylistCreate Func _PlaylistDisplay() ; _ArrayDisplay($aPlaylist) (press Ctrl+Alt+L) If $iFullScreen = 1 Then Return If WinExists("Playlist") Then WinClose("Playlist") Else _ArrayDisplay($aPlaylist, "Playlist") EndIf EndFunc ; _PlaylistDisplay Func _PlayPause() _mpv_command($pHandle, "cycle", "pause") If GUICtrlRead($idPlay2) = "❚❚" Then GUICtrlSetData($idPlay2, "▶") Else GUICtrlSetData($idPlay2, "❚❚") EndIf EndFunc Func _PlayNext() ; Play next file (click "▶" $hVCGui or press Ctrl+Alt+Right) $iRepeatCurrentFile = 0 ; Turn off file repeat mode GUICtrlSetData($idRepeat2, "U") _mpv_command($pHandle, "stop") EndFunc ; _PlayNext Func _PlayPrevious() ; Play privious file (click "◀" in $hVCGui or press Ctrl+Alt+Left) $iRepeatCurrentFile = 0 ; Turn off file repeat mode GUICtrlSetData($idRepeat2, "U") $iPlayPrevious = 1 _mpv_command($pHandle, "stop") EndFunc ; _PlayPrevious Func _Progress() ; Adlib to update position of progress bar and current position label in $hVCGui Local $sPause = _mpv_get_property($pHandle, "pause") If $sPause = "yes" then Return Local $sCurRaw = _mpv_get_property($pHandle, "time-pos", "double") Local $iCur = Int($sCurRaw) GUICtrlSetData($idCurrentPos2, _SecondsToTime($iCur)) GUICtrlSetPos($idProgBar2, $iCur/$iMediaLength*$iSliderLength2) EndFunc ; _Progress Func _SecondsToTime($iSeconds) ; Transform seconds to 00:00:00 time format Local $iH = Int($iSeconds / 3600) Local $iM = Int(Mod($iSeconds, 3600) / 60) Local $iS = Mod($iSeconds, 60) Return StringFormat("%02d:%02d:%02d", $iH, $iM, $iS) EndFunc ; _SecondsToTime Func _Slider() ; Drag and drop the progrss bar or click anywhere on the slider to jump to a new media position AdlibUnRegister("_Progress") Local $x2, $mediaPos, $lastMediaPos = -1 While _IsPressed("01", $hUser32DLL) $x2 = MouseGetPos(0) - ($aPos[0] + $iProgBarWidth / 2) ; Clamp If $x2 > $iSliderLength2 Then $x2 = $iSliderLength2 If $x2 < 0 Then $x2 = 0 $mediaPos = Int($x2 / $iSliderLength2 * $iMediaLength) GUICtrlSetPos($idProgBar2, $x2) GUICtrlSetData($idCurrentPos2, $mediaPos) Sleep(10) WEnd If $mediaPos <> $lastMediaPos Then _mpv_command($pHandle, "seek", $mediaPos, "absolute") $lastMediaPos = $mediaPos EndIf AdlibRegister("_Progress") EndFunc ; _Slider Func _SpeedDown() _mpv_command($pHandle, "add", "speed", "-0.1") Local $currentSpeed = _mpv_get_property($pHandle, "speed", "double") Local $osdText = "Speed: " & StringFormat("%.1f", $currentSpeed) & "x" _mpv_command($pHandle, "show-text", $osdText, "2000") EndFunc Func _SpeedRevert() _mpv_command($pHandle, "set", "speed", "1.0") _mpv_command($pHandle, "show-text", "Speed: 1.0x", "2000") EndFunc Func _SpeedUp() _mpv_command($pHandle, "add", "speed", "0.1") Local $currentSpeed = _mpv_get_property($pHandle, "speed", "double") Local $osdText = "Speed: " & StringFormat("%.1f", $currentSpeed) & "x" _mpv_command($pHandle, "show-text", $osdText, "2000") EndFunc Func _VCCreate() ; Create $hVCGui and video controls $iVCLeft = ($iClientWidth-$iVideoWidth)/2 $iVCTop = ($iClientHeight-$iVideoWidth)/2 $hVCGui = GUICreate("", $iVideoWidth, $iVCHeight, $iVCLeft, $iVCTop, $WS_POPUP, $WS_EX_LAYERED, $hVideoGUI) GUISetFont(10, 400, 0, "Arial", $hVCGui) $idSlider2 = GUICtrlCreateLabel("", 0, 0, $iVideoWidth, 14, BitOR($SS_NOPREFIX, $SS_LEFTNOWORDWRAP)) GUICtrlSetBkColor(-1, 0xD0D0D0) GUICtrlSetFont(-1, 10) GUICtrlSetResizing(-1, $GUI_DOCKBORDERS) $idRepeatAB2 = GUICtrlCreateLabel("", 0, 2, 10, 12) ; Pink bar to indicate A-B repeat positions in slider GUICtrlSetBkColor(-1, 0xD580FF) GUICtrlSetResizing(-1, $GUI_DOCKSIZE) GUICtrlSetState(-1, $GUI_HIDE) $idProgBar2 = GUICtrlCreateLabel("", 0, 2, $iProgBarWidth, 12) GUICtrlSetBkColor(-1, 0x566573) GUICtrlSetResizing(-1, $GUI_DOCKSIZE) $idCurrentPos2 = GUICtrlCreateLabel("00.00", 20, 18, 60, 15, $SS_LEFT) GUICtrlSetFont(-1, 10, 600) GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKSIZE) $idLength2 = GUICtrlCreateLabel("00:00", $iVideoWidth-80, 18, 60, 15, $SS_RIGHT) GUICtrlSetFont(-1, 10, 600) GUICtrlSetResizing(-1, $GUI_DOCKRIGHT+$GUI_DOCKSIZE) $idExit = GUICtrlCreateLabel("🞭", $iVideoWidth/2-109, 18, 15, 25, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont(-1, 21, 400) GUICtrlSetResizing(-1, $GUI_DOCKHCENTER+$GUI_DOCKBOTTOM+$GUI_DOCKSIZE) $idPlay2 = GUICtrlCreateLabel("❚❚", $iVideoWidth/2-69, 22, 16, 18, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont($idPlay2, 17) GUICtrlSetResizing(-1, $GUI_DOCKHCENTER+$GUI_DOCKBOTTOM+$GUI_DOCKSIZE) $idPrevious2 = GUICtrlCreateLabel("◀", $iVideoWidth/2-37, 23, 16, 18, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont(-1, 13) GUICtrlSetResizing(-1, $GUI_DOCKHCENTER+$GUI_DOCKBOTTOM+$GUI_DOCKSIZE) If $iRepeatCurrentFile = 1 Then $idRepeat2 = GUICtrlCreateLabel("0", $iVideoWidth/2-23, 23, 16, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE)) Else $idRepeat2 = GUICtrlCreateLabel("U", $iVideoWidth/2-23, 23, 16, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE)) EndIf GUICtrlSetFont(-1, 10, 900) GUICtrlSetResizing(-1, $GUI_DOCKHCENTER+$GUI_DOCKBOTTOM+$GUI_DOCKSIZE) $idNext2 = GUICtrlCreateLabel("▶", $iVideoWidth/2-8, 23, 16, 18, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont(-1, 13) GUICtrlSetResizing(-1, $GUI_DOCKHCENTER+$GUI_DOCKBOTTOM+$GUI_DOCKSIZE) $idSpeaker2 = GUICtrlCreateLabel("🔊", $iVideoWidth/2+24, 22, 16, 18, BitOR($SS_CENTER, $SS_CENTERIMAGE)) If $iMute = 1 Then GUICtrlSetData($idSpeaker2, "🔇") EndIf GUICtrlSetFont(-1, 15, 400) GUICtrlSetResizing(-1, $GUI_DOCKHCENTER+$GUI_DOCKBOTTOM+$GUI_DOCKSIZE) $idUp2 = GUICtrlCreateLabel("▲", $iVideoWidth/2+40, 17, 15, 15, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont(-1, 10) GUICtrlSetResizing(-1, $GUI_DOCKHCENTER+$GUI_DOCKBOTTOM+$GUI_DOCKSIZE) GUICtrlSetTip(-1, $iVolume) $idDown2 = GUICtrlCreateLabel("▼", $iVideoWidth/2+40, 31, 15, 15, $SS_CENTER);, $SS_CENTERIMAGE)) GUICtrlSetFont(-1, 10) GUICtrlSetResizing(-1, $GUI_DOCKHCENTER+$GUI_DOCKBOTTOM+$GUI_DOCKSIZE) GUICtrlSetTip(-1, $iVolume) $idFullScreen = GUICtrlCreateLabel("⇔", $iVideoWidth/2+70, 18, 20, 24, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont(-1, 20, 600) If $iFullScreen = 1 Then GUICtrlSetData($idFullScreen, "⇙") EndIf GUICtrlSetResizing(-1, $GUI_DOCKHCENTER+$GUI_DOCKBOTTOM+$GUI_DOCKSIZE) GUISetState(@SW_SHOW, $hVCGui) EndFunc ; _VCCreate Func _VCResize() ; Resize video control when the size or position of $hVideoGUI is changed $aPos = WinGetPos($hVideoGUI) $iSliderLength2 = $aPos[2]-$iBorderWidth*2-$iProgBarWidth WinMove($hVCGui, "", $aPos[0]+$iBorderWidth, $aPos[1]+$aPos[3]-$iVCHeight-$iBorderWidth, $aPos[2]-$iBorderWidth*2, $iVCHeight) EndFunc ; _VCResize Func _VCShow() ; Adlib function to show video controls when mouse hovers the bottom area of $hVidoGUI ; Show video control when mouse pointer enters the lower side of video window, 250ms If WinGetState($hVideoGUI) < 7 Then Return Local $aPos1 = WinGetPos($hVideoGUI), $iLeft, $iTop, $iRight, $iBottom If Not IsArray($aPos1) Then Return $iLeft = $aPos1[0] $iRight = $aPos1[0]+$aPos1[2] $iBottom = $aPos1[1]+$aPos1[3] $iTop = _Max($iBottom-150, $aPos1[1]) Local $iX = MouseGetPos(0), $iY = MouseGetPos(1), $iTransColor, $iAlpha _WinAPI_GetLayeredWindowAttributes($hVCGui, $iTransColor, $iAlpha) If $iAlpha <> 0 And ($iX <= $iLeft Or $iX >= $iRight Or $iY <= $iTop Or $iY >= $iBottom) Then WinSetTrans($hVCGui, "", 0) ; Fully transparent (invisible) ElseIf $iAlpha <> 150 And $iX > $iLeft And $iX < $iRight And $iY > $iTop And $iY < $iBottom Then WinSetTrans($hVCGui, "", 150) ; Partly transparent (150/255) EndIf If $iMaximized + $iFullScreen = 0 Then $aPrePos = WinGetPos($hVideoGUI) EndIf EndFunc ; _VCShow Func _VideoRefresh() ; Adlib to give a heartbeat to the video renderer every 5 minutes ; Check if the center of the video window is visible on the screen ; Position of video window ($aPos) is updated by WM_WINDOWPOSCHANGED in real time Local $tPoint = _WinAPI_CreatePoint($aPos[0]+$aPos[2]/2, $aPos[1]+$aPos[3]/2) Local $hTopWnd = _WinAPI_WindowFromPoint($tPoint) If $hTopWnd = $hVideoGUI Then Return ; Return if visible _mpv_command($pHandle, "seek", 0.05, "relative") _mpv_command($pHandle, "seek", -0.05, "relative") ; Please let me know if anyone knows of a less intrusive way to keep the video renderer alive while in background EndFunc ; _VideoRefresh Func _VideoResize() ; Resize $hVideoGUI WinSetTrans($hVCGui, "", 0) Local $iVideoWidth, $iVideoHeight, $x, $y, $w, $h $aPos = WinGetPos($hVideoGUI) $iVideoWidth = $aPos[2] - $iBorderWidth*2 $iVideoHeight = Round($iVideoWidth/$iAspect) If $iVideoHeight > $iClientHeight-$iTitleHeight-$iBorderWidth Then $iVideoHeight = $iClientHeight-$iTitleHeight-$iBorderWidth $iVideoWidth = Round($iVideoHeight*$iAspect) EndIf $w = $iVideoWidth+$iBorderWidth*2 $h = $iVideoHeight+$iTitleHeight+$iBorderWidth $x = ($iClientWidth-$w)/2 $y = ($iClientHeight-$h)/2 WinMove($hVideoGUI, "", $x, $y, $w, $h) _VCResize() EndFunc ;==>_VideoResize Func _mpv_command($ptr, $p1, $p2 = "", $p3 = "", $p4 = "") ; Call mpv_command with variable number of parameters ; 1. Count the number of params passed Local $iCount = 1 If $p2 <> "" Then $iCount = 2 If $p3 <> "" Then $iCount = 3 If $p4 <> "" Then $iCount = 4 ; 2. Create pointer arrays (number of params + 1 null) Local $tPtrArray = DllStructCreate("ptr[" & ($iCount + 1) & "]") ; 3. Assign strings to local memory variables Local $aStrStructs[$iCount] Local $aParams = [$p1, $p2, $p3, $p4] For $i = 0 To $iCount - 1 $aStrStructs[$i] = DllStructCreate("char[" & StringLen($aParams[$i]) + 1 & "]") DllStructSetData($aStrStructs[$i], 1, $aParams[$i]) DllStructSetData($tPtrArray, 1, DllStructGetPtr($aStrStructs[$i]), $i + 1) Next DllStructSetData($tPtrArray, 1, 0, $iCount + 1) ; 4. Call mpv_command Local $aRet = DllCall($hMPV_DLL, "int:cdecl", "mpv_command", "ptr", $ptr, "ptr", DllStructGetPtr($tPtrArray)) Return $aRet EndFunc ; _mpv_command Func _mpv_free($pAddr) ; Prevent memory leak ; Omitting :cdecl in an AutoIt DllCall leads to stack corruption, which can cause ignored commands or program termination DllCall($hMPV_DLL, "void:cdecl", "mpv_free", "ptr", $pAddr) EndFunc ; _mpv_free Func _mpv_get_property($hMpv, $sProperty, $sType = "string") ; Get MPV properties, string or double Local $vResult = "" Switch StringLower($sType) Case "string", "str" Local $aRet = DllCall($hMPV_DLL, "ptr:cdecl", "mpv_get_property_string", "ptr", $hMpv, "str", $sProperty) If Not @error And $aRet[0] <> 0 Then Local $iLen = _mpv_get_strlen($aRet[0]) $vResult = DllStructGetData(DllStructCreate("char[" & $iLen & "]", $aRet[0]), 1) DllCall($hMPV_DLL, "none:cdecl", "mpv_free", "ptr", $aRet[0]) EndIf Case "double", "num", "number" Local $tDouble = DllStructCreate("double") Local $aRet = DllCall($hMPV_DLL, "int:cdecl", "mpv_get_property", "ptr", $hMpv, "str", $sProperty, "int", 5, "ptr", DllStructGetPtr($tDouble)) If $aRet[0] < 0 Then Return 0 ; Error Return DllStructGetData($tDouble, 1) Case Else Return SetError(1, 0, "Unknown Type") EndSwitch Return $vResult EndFunc ; mpv_get_property Func _mpv_get_strlen($pPtr) ; Local $aRet = DllCall("kernel32.dll", "int", "lstrlenA", "ptr", $pPtr) Return $aRet[0] EndFunc Func _mpv_set_options() ; set initial options for smooth operation ; Set hardware acceleration options (Based on Media Foundation) Local $sSpec = _GetVideoCardSpec() If $sSpec = "low" Then _mpv_set_option_string($pHandle, "profile", "fast") _mpv_set_option_string($pHandle, "vo", "direct3d") _mpv_set_option_string($pHandle, "dither", "no") _mpv_set_option_string($pHandle, "framedrop", "vo") Else _mpv_set_option_string($pHandle, "profile", "gpu-hq") _mpv_set_option_string($pHandle, "vo", "gpu") EndIf _mpv_set_option_string($pHandle, "gpu-api", "d3d11") _mpv_set_option_string($pHandle, "hwdec", "d3d11va") _mpv_set_option_string($pHandle, "scale", "bilinear") _mpv_set_option_string($pHandle, "cscale", "bilinear") _mpv_set_option_string($pHandle, "dscale", "bilinear") ; Additional options available for higher spec computers to improve video quality ; _mpv_set_option_string($pHandle, "video-sync", "display-resample") ; _mpv_set_option_string($pHandle, "interpolation", "yes") ; _mpv_set_option_string($pHandle, "tscale", "oversample") ; _mpv_set_option_string($pHandle, "scale", "extir-lanczos") ; or "spline36" ; _mpv_set_option_string($pHandle, "cscale", "lanczos") ; _mpv_set_option_string($pHandle, "dscale", "mitchell") ; Set maximum volume ;_mpv_set_property_string($pHandle, "volume-max", "100") _mpv_set_property($pHandle, "volume-max", 100.0, "double") ; Connet GUI handle (Display video in an AutoIt GUI) _mpv_set_option_string($pHandle, "wid", String(Ptr($hVideoGUI))) _mpv_set_option_string($pHandle, "idle", "yes") EndFunc ; mpv_set_options Func _mpv_set_option_string($ptr, $name, $value) ; get mpv propertiess in string format DllCall($hMPV_DLL, "int:cdecl", "mpv_set_option_string", "ptr", $ptr, "str", $name, "str", $value) EndFunc ; _mpv_set_option_string Func _mpv_set_property($hMpv, $sProperty, $vValue, $sType = "string") ; 0 = MPV_FORMAT_STRING Local $aRet Switch $sType Case "string", "str" $aRet = DllCall($hMPV_DLL, "int:cdecl", "mpv_set_property_string", "ptr", $hMpv, "str", $sProperty, "str", String($vValue)) Case "double", "num", "number" Local $tDouble = DllStructCreate("double") DllStructSetData($tDouble, 1, Number($vValue)) $aRet = DllCall($hMPV_DLL, "int:cdecl", "mpv_set_property", "ptr", $hMpv, "str", $sProperty, "int", 5, "ptr", DllStructGetPtr($tDouble)) Case Else Return SetError(1, 0, -1) EndSwitch Return $aRet[0] EndFunc Func WM_WINDOWPOSCHANGED($hWnd, $MsgID, $wParam, $lParam) ; Sync movement of $hVideoGUI and $hVCGui #forceref $hWnd, $MsgID, $wParam, $lParam Local $aPos1 If $iFullScreen = 0 Then _VCResize() Sleep(10) If $iMaximized = 1 And WinGetState($hVideoGUI) < 32 Then $iMaximized = 0 ; Maximized window was dragged downward causing restoration EndIf EndIf Return $GUI_RUNDEFMSG EndFunc ; WM_WINDOWPOSCHANGED