CYCho Posted August 1, 2020 Share Posted August 1, 2020 (edited) Hi there! I wish every one of you to be healthy and happy. I made the following code borrowing mainly from @dragan's post. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <IE.au3> Global $mainGUI = GUICreate("Load and play a video file", 400, 200, -1, -1) Global $inputFile = GUICtrlCreateInput("", 20, 50, 280, 20) Global $btnLoad = GUICtrlCreateButton("Load", 300, 48, 80, 23) Global $btnPlay = GUICtrlCreateButton("Play", 160, 100, 80, 23) GUISetState() Global $videoHeight = @DesktopHeight/2, $videoWidth = $videoHeight, $videoLeft = @DesktopWidth-$videoWidth, $IEControl Global $videoGUI = GUICreate("Video Control", $videoWidth, $videoHeight, $videoLeft, 0, $WS_OVERLAPPEDWINDOW) Global $oIE = _GUICtrl_CreateWMPlayer() GUISetState (@SW_HIDE, $videoGUI) GUIRegisterMsg($WM_SIZE, "WM_SIZE") Global $oPlayer = _IEGetObjById($oIE, "objWMPlayer") Global $aMsg While 1 $aMsg = GUIGetMsg(1) If $aMsg[1] = $mainGUI Then If $aMsg[0] = $GUI_EVENT_CLOSE Then Exit ElseIf $aMsg[0] = $btnLoad Then Local $sFile = FileOpenDialog("Open Videos", @UserProfileDir, "Movies (*.3gp;*.mp4;*.avi;*.wmv;*.flv)") GUICtrlSetData($inputFile, $sFile) If @error Then Exit ElseIf $aMsg[0] = $btnPlay Then GUISetState(@SW_SHOW, $videoGUI) $oPlayer.URL = $sFile $oPlayer.Controls.Play While $oPlayer.playState <> 3 Sleep(10) WEnd Local $sWidth = $oPlayer.currentMedia.imageSourceWidth, $sHeight = $oPlayer.currentMedia.imageSourceHeight If $sWidth > 0 Then Local $iWidth = $videoHeight*$sWidth/$sHeight WinMove($videoGUI, "", @DesktopWidth-$iWidth, 0, $iWidth+16, $videoHeight+39) EndIf EndIf ElseIf $aMsg[1] = $videoGUI And $aMsg[0] = $GUI_EVENT_CLOSE Then $oPlayer.Controls.Stop GUISetState (@SW_HIDE, $videoGUI) ContinueLoop ElseIf $oPlayer.playState = 1 Or $oPlayer.playState = 8 Then GUISetState (@SW_HIDE, $videoGUI) ContinueLoop EndIf WEnd Func WM_SIZE($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam, $ilParam Local $xClient, $yClient $xClient = BitAND($ilParam, 0x0000FFFF) $yClient = BitShift($ilParam, 16) GUICtrlSetPos($IEControl, 0, 0, $xClient, $yClient) if NOT @error Then if IsObj($oPlayer) Then $oPlayer.width = $xClient; if IsObj($oPlayer) Then $oPlayer.height = $yClient; EndIf Return $GUI_RUNDEFMSG EndFunc Func _GUICtrl_CreateWMPlayer() Local $myIE_Obj = _IECreateEmbedded () $IEControl = GUICtrlCreateObj($myIE_Obj, 0, 0, $videoWidth, $videoHeight) _IENavigate($myIE_Obj, "about:blank") Local $htmlWMP $htmlWMP = '' _ & @CR & '<body style="margin:0;padding:0" >' _ & @CR & '<OBJECT' _ & @CR & 'ID="objWMPlayer"' _ & @CR & 'STYLE="margin:0;padding:0"' _ & @CR & 'HSPACE="0"' _ & @CR & 'VSPACE="0"' _ & @CR & 'BORDER="0"' _ & @CR & 'WIDTH="' & $videoWidth & '"' _ & @CR & 'HEIGHT="' & $videoHeight & '"' _ & @CR & 'CLASSID="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6"' _ & @CR & 'STANDBY="Loading Windows Media Player components..."' _ & @CR & 'TYPE="application/x-ms-wmp">' _ & @CR & '<PARAM NAME="enableContextMenu" VALUE="true">' _ & @CR & '<PARAM NAME="enableFullScreenControls" VALUE="true">' _ & @CR & '<PARAM NAME="enabled" VALUE="true">' _ & @CR & '<PARAM NAME="playCount" VALUE="1">' _ & @CR & '<PARAM NAME="stretchToFit" VALUE="true">' _ & @CR & '<PARAM NAME="uiMode" VALUE="none">' _ & @CR & '<PARAM NAME="videoBorderWidth" VALUE="5">' _ & @CR & '<PARAM NAME="volume" VALUE="100">' _ & @CR & '<PARAM NAME="windowlessVideo" VALUE="false">' _ & @CR & '</OBJECT>' _ & @CR & '</body>' _IEDocWriteHTML ($myIE_Obj, $htmlWMP) _IEAction ($myIE_Obj, "refresh") $myIE_Obj.document.body.scroll = "no" $myIE_Obj.document.body.style.borderColor = "#000000" Return $myIE_Obj EndFunc ;==>_GUICtrl_CreateWMPlayer This works usually OK, but the embedded WMP behaves abnormally when the 2 windows are minimized and restored depending on which one is minimized and restored first. While video is playing: 1. Minimize $mainGUI, then the $videoGUI becomes blank. 2. Minimize both and restore $videoGUI first and then the $mainGUI, then the video size in the $videoGUI is changed to it's original source image size. Please help me to understand what is the cause of this behaviour and how I can prevent it. Thnaks in advance. Edited August 1, 2020 by CYCho zPlayer - A Small Audio and Video Player Time Sync + SystemTimeAdjustment Link to comment Share on other sites More sharing options...
CYCho Posted August 1, 2020 Author Share Posted August 1, 2020 (edited) I found the cause and the problem was solved. The culprit was WM_SIZE function which is triggered not only by $videoGUI but also by any window. So I added If $hWnd <> $videoGUI Then Return 0 in the beginning of the function and the problem is gone. Thanks for your attention. Edited August 11, 2020 by CYCho zPlayer - A Small Audio and Video Player Time Sync + SystemTimeAdjustment Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now