Issue with Windows Media Player

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Issue with Windows Media Player

27 Oct 2023, 17:50

I use Windows Media Player to play video inside an AHK Gui. Here's the basic code for creating a video:

Code: Select all

SysGet, n, monitorcount
Loop, % n
{
	SysGet, M, Monitor, %A_Index%
	
	MX%A_index% := Mleft
	MY%A_index% := MTop
	MW%A_index% := MRight  - MLeft
	MH%A_index% := MBottom - MTop

	Global X_ := Mleft
	Global Y_ := MTop
	Global W_ := MRight  - MLeft
	Global H_ := MBottom - MTop
}

Gui, Vid:New, +alwaysontop -Caption +owndialogs +HwndVNP -dpiscale, Video Now Playing ;+E0x02000000 +E0x00080000
Gui, color, black	

Gui, Add, ActiveX, x0 y0  w%W_% h%H_% vWMP, WMPLayer.OCX 

WMP.uiMode := "none"                         ; no WMP controls
WMP.stretchToFit := 1                        ; video is stretched to the given activex range
WMP.enableContextMenu := 0                   ; no reaction to right click in the video field

Gui, Show, x%X_% y%Y_% hide, Video Now Playing	;initially hidden to avoid black screen before the video starts
Clip := WMP.newMedia(Now)          ; create a new Media object, now = path to chosen video
Dur:= Clip.getItemInfo("Duration")    ; get its duration

WMP.currentMedia := Clip                    ; set the players 'currentMedia' object
WMP.controls.play                            ; play
sleep 1000

Gui, Vid:show,noactivate x%X_% y%Y_% h%H_% w%W_%	;coordinates of second monitor
The issue I'm having is that sometimes when I first try to play a video it starts and then immediately stops. Thereafter videos load and play correctly. Is there anything in my code posted here that could be causing this? Is there any more reliable way to play a video inside a GUI using WMP? Thanks.
User avatar
mikeyww
Posts: 27373
Joined: 09 Sep 2014, 18:38

Re: Issue with Windows Media Player

29 Oct 2023, 06:44

🢂 WARNING 🢀

The last line of the script displays a full-screen on-top window. The script contains no built-in way to quit or exit. I recommend NOT running this script on systems with a single monitor.
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Re: Issue with Windows Media Player

01 Nov 2023, 07:18

Thanks for the warning. I will add some code that prevents the video from running unless there is more than one monitor. Can you think of a way to check if the video player fails to initiate?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: effel, Marium0505, pond_pop and 114 guests