VocabMike Posted October 4, 2023 Posted October 4, 2023 I have put this code together from examples and it works well but the exit procedure, based on a pixel search of 0, is not ideal. Could any of the more experienced coders suggest a more robust method? #include <windowsconstants.au3> _Run_Video() Func _Run_Video() Local $sVideoFileName = "FileNameHere" Local $hForm, $iCtrlID Local $oShell, $sInnerHTML, $iColor, $Loop = 1 $hForm = GUICreate("", 800, 450, -1, -1, $WS_POPUP) $sInnerHTML = '<object id="player" height="100%" width="100%" align="middle" ' & _ 'classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"> ' & _ ' <param name="URL" value="' & $sVideoFileName & '">' & _ ' <param name="uiMode" value="none"> ' & _ ' <param name="fullScreen" value="false"> ' & _ ' <param name="ShowControls" value="true"> ' & _ ' <param name="ShowStatusBar" value="true"> ' & _ ' <param name="ShowDisplay" value="true"> ' & _ ' <embed type="application/x-mplayer2" ' & _ ' pluginspage = "http://www.microsoft.com/Windows/MediaPlayer/" ' & _ ' SRC="' & $sVideoFileName & '"' & _ '</embed></object>' $oShell = ObjCreate("Shell.Explorer.2") $iCtrlID = GUICtrlCreateObj($oShell, -1, -1, 801, 451) $oShell.navigate("about:blank") While $oShell.Busy() Sleep(10) WEnd With $oShell.document .write('<HEAD><TITLE></TITLE><script language="javascript"></script></HEAD>') .write('<body onselectstart="return false" oncontextmenu="return false" onclick="return false" ondragstart="return false" ondragover="return false">') .body.innerHTML = $sInnerHTML .body.topmargin = 0 .body.leftmargin = 0 .body.scroll = "no" .body.bgcolor = 0xFFFFFF .body.style.borderWidth = 0 EndWith GUISetState() While $oShell.Busy() Sleep(10) WEnd While $Loop = 1 Sleep(1000) ; Allows Video to start before looking for end of Video... ;If PixelGetColor(@DesktopWidth / 2, @DesktopHeight / 2, $hForm) = 0 Then $Loop = 0 ; Exit $Loop If $oShell.Stop = True Then $Loop = 0 ; Exit $Loop WEnd GUIDelete() EndFunc ;==>_Run_Video
Andreik Posted October 4, 2023 Posted October 4, 2023 Is there any specific reason why do you create a ShellExplorer object and then you embed WMP as an object? You can work directly with WMP. Local $sFile = "<path to your file>" $oWMP = ObjCreate("WMPlayer.ocx") $hMain = GUICreate('Player', 800, 600, -1, -1, 0x80000000) $hActiveX = GUICtrlCreateObj($oWMP, 0, 0, 800, 600) GUISetState(@SW_SHOW, $hMain) With $oWMP .UIMode = "none" .EnableContextMenu = True .WindowlessVideo = True .Url = $sFile .Settings.AutoStart = True EndWith Do If $oWMP.playState = 1 Then ConsoleWrite('Video ended.' & @CRLF) Sleep(10) Until GUIGetMsg() = -3 $oWMP.Close()
VocabMike Posted October 5, 2023 Author Posted October 5, 2023 Thanks for the prompt reply Andreik. The video plays and exits as required but does not fit within the bounderies of the GUI... it plays "full screen" and only the top left portion of the video is visible in the window. I searched for similar use of the "$oWMP object switches to include... ( .fullscreen = true/false and .stretchToFit = true) but no joy. I am a bit of a novice here, I know the basics but still learning so any further guidance would be appreciated.
Musashi Posted October 5, 2023 Posted October 5, 2023 Maybe this helps : https://learn.microsoft.com/en-us/windows/win32/wmp/axwindowsmediaplayer-object--vb-and-c stretchToFit Gets or sets a value indicating whether video will stretch to fit size of the Windows Media Player control video display. "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."
Solution Andreik Posted October 5, 2023 Solution Posted October 5, 2023 (edited) A little bit hacky but it works. expandcollapse popup#include <IE.au3> Local $sFile = "<path to your video file>" $oIE = _IECreateEmbedded() Local $hForm = GUICreate("", 800, 450, -1, -1, 0x80000000) Local $iCtrlID = GUICtrlCreateObj($oIE, 0, 0, 800, 450) _IENavigate($oIE, 'about:blank') $oIEEvents = ObjEvent($oIE, '_IEEvent_', 'DWebBrowserEvents2') _IEHeadInsertEventScript($oIE, 'document', 'oncontextmenu', 'return false') _IEHeadInsertEventScript($oIE, 'document', 'onselectstart', 'return false') _IEHeadInsertEventScript($oIE, 'document', 'onclick', 'return false') _IEHeadInsertEventScript($oIE, 'document', 'ondragstart', 'return false') _IEHeadInsertEventScript($oIE, 'document', 'ondragover', 'return false') With $oIE.document .body.topmargin = 0 .body.leftmargin = 0 .body.scroll = 'no' .body.bgcolor = 0xFFFFFF .body.style.borderWidth = 0 EndWith Local $sHTML $sHTML &= '<object id="player" height="100%" width="100%" align="middle" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6">' $sHTML &= ' <param name="URL" value="' & $sFile & '">' $sHTML &= ' <param name="uiMode" value="none">' $sHTML &= ' <param name="fullScreen" value="false">' $sHTML &= ' <param name="ShowControls" value="false">' $sHTML &= ' <param name="ShowStatusBar" value="true">' $sHTML &= ' <param name="ShowDisplay" value="true">' $sHTML &= ' <param name="enableContextMenu" value="false">' $sHTML &= '</object>' Local $sGetStatus $sGetStatus &= 'Player = document.getElementById("player");' $sGetStatus &= 'interval = setInterval(GetStatus, 1000);' $sGetStatus &= 'function GetStatus() {' $sGetStatus &= ' if(Player.playState === 1 || Player.playState === 9) {' $sGetStatus &= ' clearInterval(interval);' $sGetStatus &= ' document.title = "whatever"' $sGetStatus &= ' }' $sGetStatus &= '}' _IEBodyWriteHTML($oIE, $sHTML) $oIE.document.parentwindow.setTimeout($sGetStatus, 0) GUISetState() Do Sleep(10) Until GUIGetMsg() = -3 Func _IEEvent_TitleChange($sTitle) ConsoleWrite('Video just ended.' & @CRLF) EndFunc Edited October 5, 2023 by Andreik
Andreik Posted October 5, 2023 Posted October 5, 2023 @ioa747 It looks like you need some specific codecs to work or it's again Win 11 messed up. I use MP Classic on a daily basis to play all kinds of video files and works well but I can't play a single file with zPlayer because it complains about missing codecs. ioa747 1
ioa747 Posted October 5, 2023 Posted October 5, 2023 (edited) And a extra code pack will not help you? i usual install the mega pack from https://www.codecguide.com/download_kl.htm Of course , I don't have win11 Edited October 5, 2023 by ioa747 CYCho and Andreik 1 1 I know that I know nothing
Andreik Posted October 5, 2023 Posted October 5, 2023 Most probably it will but I was curious if anyone know exactly what codec it's used. It's a little bit too much to install a bunch of codecs with hope that one will match the requirements. I have Win 10 in VM, I'll do some research when I get a little bit of time.
ioa747 Posted October 5, 2023 Posted October 5, 2023 23 minutes ago, Andreik said: what codec it's used for this i use https://mediaarea.net/en/MediaInfo , and in option check the 'Explorer Tooltip (in Windows Explorer, move the mouse over the file, info will be displayed)' 26 minutes ago, Andreik said: too much to install a bunch of codecs if there was one file type, all of this wouldn't be needed but when you need it to be available to play the video , instead of a msg about missing codecs. I know that I know nothing
VocabMike Posted October 7, 2023 Author Posted October 7, 2023 Thank you all for your help and suggestions. Added an Exit statement to Andreik "hack"... call it what you like it worsks for me... Cheers. Thanks for the Propertise info Musashi have copied this for future reference. Will also have a play with ioa747 and CYCHo Players, again for future use.
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