#include-once #include #CS Title: Windows Media Player UDF Library for AutoIt3 Filename: WMP.au3 Description: A collection of functions for creating and controlling a Windows Media Player GUI control in AutoIT Author: SudeepJD Version: V0.1 Last Update: 21/06/20 Requirements: AutoIt3 3.2 or higher, A Windows Media Player version greater than 7.0 installed Changelog: ---------21/06/20---------- v0.1 Initial release. #CE ;Global Variables Global $oWMPErrorHandler, $sWMPUserErrorHandler ; #FUNCTION# ;=============================================================================== ; ; Name...........: _GUICtrlWMP_Create() ; Description ...: Creates a Windows Media Player control. ; Syntax.........: _GUICtrlWMP_Create($left, $top, $width, $height, $show_controls) ; Parameters ....: $left - The left side of the control. ; $top - The top of the control. ; $width - The width of the control ; $height - The height of the control ; $show_controls - Whether to show the control or not ; Return values .: On Success - Returns the identifier (controlID) of the new control. ; On Failure - Returns False. ; Remarks .......: This function must be used before any other function in the UDF is used. ; ;========================================================================================== Func _GUICtrlWMP_Create($left, $top, $width, $height, $show_controls = False) Local Const $html = _ "" & @CRLF & _ "" & @CRLF & _ "" $oIE = _IECreateEmbedded () $oIEActiveX = GUICtrlCreateObj($oIE, $left, $top, $width-4, $height-4) _IENavigate($oIE, "about:blank") _IEDocWriteHTML($oIE, $html) _IELoadWait($oIE) $wmp = _IEGetObjById($oIE, "wmp") ; Clear any current VLC errors $oWMPErrorHandler.WinDescription = "" ; Check VLC version info. as a means to determine if the Active X control is installed $wmp.versionInfo() ; If an error (the ActiveX control is not installed), then return False If StringInStr($oWMPErrorHandler.WinDescription, "Unknown name") > 0 Then GUICtrlDelete($oIEActiveX) _IEQuit($oIE) Return False EndIf ;Remove the UI controls If $show_controls == False Then $wmp.uiMode = 'none' $wmp.settings.autoStart = False Return $wmp EndFunc ; #FUNCTION# ;=============================================================================== ; ; Name...........: _GUICtrlWMP_Load() ; Description ...: Loads a file into the WMP to be played ; Syntax.........: _GUICtrlWMP_Load($left, $top, $width, $height, $show_controls) ; Parameters ....: $wmp - The WMP Object. ; $url - The Path of the file to be played. ; $autostart - Should the video play immideately on being loaded ; Return values .: None ; Remarks .......: ; ;========================================================================================== Func _GUICtrlWMP_Load($wmp, $url, $autostart = True) If IsObj($wmp) = False Then Return False $wmp.URL = $url If $autostart = True Then $wmp.controls.play() EndFunc ; #FUNCTION# ;=============================================================================== ; ; Name...........: _GUICtrlWMP_Action() ; Description ...: Executes and action or returns data from the WMP Control ; Syntax.........: _GUICtrlWMP_Action($wmp, $action, $value) ; Parameters ....: $wmp - The WMP Object. ; $action - The Action to be performed. ; $value - Optional value to update the WMP Control with ; Return values .: The actions can be looked at from the function below ; Remarks .......: ; ;========================================================================================== Func _GUICtrlWMP_Action($wmp, $action = "", $value = "") If IsObj($wmp) = False Then Return False If $action = "" Then ConsoleWriteError("WMP : Please specify an action" & @CRLF) Return EndIf Select Case $action = "play" If $wmp.controls.isAvailable("play") Then $wmp.controls.play() Case $action = "stop" If $wmp.controls.isAvailable("stop") Then $wmp.controls.stop() Case $action = "pause" If $wmp.controls.isAvailable("pause") Then $wmp.controls.pause() Case $action = "invisible" $wmp.uiMode = "invisible" Case $action = "controls" $wmp.uiMode = "mini" Case $action = "nocontrols" $wmp.uiMode = "none" Case $action = "fullscreen" $wmp.fullscreen = "true" Case $action = "step" If $wmp.controls.isAvailable("step") Then $wmp.controls.step($value) Case $action = "fastForward" If $wmp.controls.isAvailable("fastForward") Then $wmp.controls.fastForward() Case $action = "fastReverse" If $wmp.controls.isAvailable("fastReverse") Then $wmp.controls.fastReverse() Case $action = "volume" If $value <> "" Then If $value = 0 Then $value = 1 $wmp.settings.volume = $value Else Return $wmp.settings.volume EndIf Case $action = "mute" $wmp.settings.mute = True Case $action = "unmute" $wmp.settings.mute = False Case $action = "rate" $wmp.settings.rate = $value Case $action = "playcount" $wmp.settings.playCount = $value Case $action = "position" If $value <> "" Then $wmp.controls.currentPosition = $value Else Return $wmp.controls.currentPosition EndIf Case $action = "positionstring";Returns HH:MM:SS Return $wmp.controls.currentPositionString Case $action = "duration" Return $wmp.currentMedia.duration Case $action = "state" $pState = $wmp.playState Switch $pState Case 0 $sState = "Undefined" Case 1 $sState = "Stopped" Case 2 $sState = "Paused" Case 3 $sState = "Playing" Case 4 $sState = "Scan Forward" Case 5 $sState = "Scan Reverse" Case 6 $sState = "Buffering" Case 7 $sState = "Waiting" Case 8 $sState = "Ended" Case 9 $sState = "Transitioning" Case 10 $sState = "Ready" Case 11 $sState = "Reconnecting" Case Else $sState = "Unknown" EndSwitch Return $sState EndSelect EndFunc ; #FUNCTION# ;=============================================================================== ; ; Name...........: _WMPErrorHandlerRegister() ; Description ...: Register and enable a WMP ActiveX error handler. ; Syntax.........: _WMPrrorHandlerRegister($s_functionName = "__VLCInternalErrorHandler") ; Parameters ....: $s_functionName - The name of the AutoIT function to run if an error occurs. ; Return values .: On Success - Returns 1 ; On Failure - Returns 0 ; Author ........: SudeepJD ; Modified.......: ; Remarks .......: ; ;========================================================================================== Func _WMPErrorHandlerRegister($s_functionName = "__WMPInternalErrorHandler") _IEErrorNotify(false) $sWMPUserErrorHandler = $s_functionName $oWMPErrorHandler = "" $oWMPErrorHandler = ObjEvent("AutoIt.Error", $s_functionName) If IsObj($oWMPErrorHandler) Then SetError(0) Return 1 Else SetError(0, 1) Return 0 EndIf EndFunc ; #FUNCTION# ;=============================================================================== ; ; Name...........: __WMPInternalErrorHandler() ; Description ...: A WMP ActiveX error handler. ; Syntax.........: __WMPInternalErrorHandler() ; Parameters ....: ; Return values .: On Success - Returns 1 ; On Failure - Returns 0 ; Author ........: SudeepJD ; Modified.......: ; Remarks .......: Doesn't do anything really, except catch and set the error values in ; $oWMPErrorHandler. $oWMPErrorHandler is global, and can be utilised ; in the calling script instead. ; ;========================================================================================== Func __WMPInternalErrorHandler() ;Do Nothing Return EndFunc