Play video inside AHK GUI

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

Play video inside AHK GUI

23 Dec 2022, 17:15

I've asked something similar before,but is there a way to play an mp4 video inside a gui without using an external player - ie. just using what comes with a regular windows installation? I thought I had a solution with the following code from garry:

Code: Select all

;- not work = webm
extensions :="mp4,flv,vob,mpg,mkv"

FileSelectFile, file, 2, D:\M_MEDIA\M_VIDEO, Select WMP Compatible File:%extensions%
if Errorlevel
   ExitApp
SplitPath,file, name, dir, ext, name_no_ext, drive
If Ext not In %extensions%
{
msgbox, 262208, ,Can't PLAY`n--------------`nExtension is not in %extensions% .
exitapp
}   
  
;Gui, +LastFound +Resize
Gui,2:Color,Black
Gui,2:Color,ControlColor, Black
Gui,2: Add, ActiveX,x25 y25 w1400 h800 vWMP, WMPLayer.OCX
WMP.Url := file
WMP.uiMode := "none"                   ; no WMP controls
WMP.stretchToFit := 1                  ; video is streched to the given activex range
WMP.enableContextMenu := 0             ; no reaction to right click in the video field
WMP.settings.setMode("loop", true)
Gui,2: Show, w1450 h850 Center, Player GUI
return
2GuiClose:
ExitApp
It worked on my main machine but not on two other laptops using W10. Also I couldn't find a way to close the video after it finished playing. I tried using:

Code: Select all

WMP.settings.setMode("loop", false)
But unsurprisingly this didn't close the video. Thanks.
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Play video inside AHK GUI

24 Dec 2022, 00:50

PuzzledGreatly wrote:
23 Dec 2022, 17:15
I've asked something similar before,but is there a way to play an mp4 video inside a gui without using an external player - ie. just using what comes with a regular windows installation? I thought I had a solution with the following code from garry:

Code: Select all

;- not work = webm
extensions :="mp4,flv,vob,mpg,mkv"

FileSelectFile, file, 2, D:\M_MEDIA\M_VIDEO, Select WMP Compatible File:%extensions%
if Errorlevel
   ExitApp
SplitPath,file, name, dir, ext, name_no_ext, drive
If Ext not In %extensions%
{
msgbox, 262208, ,Can't PLAY`n--------------`nExtension is not in %extensions% .
exitapp
}   
  
;Gui, +LastFound +Resize
Gui,2:Color,Black
Gui,2:Color,ControlColor, Black
Gui,2: Add, ActiveX,x25 y25 w1400 h800 vWMP, WMPLayer.OCX
WMP.Url := file
WMP.uiMode := "none"                   ; no WMP controls
WMP.stretchToFit := 1                  ; video is streched to the given activex range
WMP.enableContextMenu := 0             ; no reaction to right click in the video field
WMP.settings.setMode("loop", true)
Gui,2: Show, w1450 h850 Center, Player GUI
return
2GuiClose:
ExitApp
It worked on my main machine but not on two other laptops using W10. Also I couldn't find a way to close the video after it finished playing. I tried using:

Code: Select all

WMP.settings.setMode("loop", false)
But unsurprisingly this didn't close the video. Thanks.
It stops playing the video, do you mean the gui that you put the video on stays?

You can close that by using

Code: Select all

Gui,2: Destroy
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Re: Play video inside AHK GUI

24 Dec 2022, 01:36

Thanks for the reply, I know I can destroy the Gui but how to do that after the video has stopped playing? I'd need a reliable way to know the length of each video loaded.
garry
Posts: 3790
Joined: 22 Dec 2013, 12:50

Re: Play video inside AHK GUI

24 Dec 2022, 09:41

PatsyCline jpg.jpg
PatsyCline jpg.jpg (508.92 KiB) Viewed 1448 times
an example ( needs videolan )
PLAY > VIDEO/MUSIC/TV EXTRA3 in GUI , see playedtime and endtime , click on progressbar or < > for forward/back

Code: Select all

;- PLAY >  VIDEO/MUSIC/TV EXTRA3  in GUI , see playedtime and endtime , click on progressbar or < >  for forward/back
;- needs videolan vlc.exe installed 
;- use ESC to STOP/PLAY  > minimize / maximize
;-
#NoEnv
SendMode,Input
SetWorkingDir, %A_ScriptDir%
SetTitleMatchMode,2
SetBatchLines, -1
wa:=A_screenwidth,ha:=A_screenHeight,xx:=100
fontsize1=12
Gui,2:default
Gui,2: +HwndAId  +0x2000000  ; +WS_CLIPCHILDREN Fixes drawing problems with child.
Gui,2: -DPIScale hwndUID
SS_REALSIZECONTROL := 0x40
Gui,2:Color,Black,Black
Gui,2:Font,s%fontsize1% cGray,Lucida Console
stringmid,datex,a_now,1,10
global C2,T2
;-
Name1=PLAY_VLC_ActiveX_MP3_MP4_Picture
;-
;======================================================
hotkey, IfWinActive,%name1% ahk_class AutoHotkeyGUI 
Hotkey,SPACE,pause1,ON

hotkey, IfWinExist,%name1% ahk_class AutoHotkeyGUI 
hotkey,ESC,aabb        

;======================================================  

;-------------------------------------------
editorx1=C:\Program Files\Notepad++\notepad++.exe
ifnotexist,%editorx1%
  editorx1:=""
vlc1  =%A_programfiles%\VideoLAN\VLC\vlc.exe    ;- VLC should be installed for ActiveX
dlm:=";"
;-
FDMusic    :="D:\M_MEDIA\M_MUSIC\M_FAVORIT"   ;- Folder Music
FDVideo    :="D:\M_MEDIA\M_VIDEO_FAVORIT"     ;- Folder Video 
FDPictures :="D:\M_MEDIA\M_FOTO\ART"          ;- Folder Pictures for random pictures used for audio-file which not contains thumbnail-picture
;-
videoextensions   :="mp4,flv,mpg,vob,m4a,avi,webm"
musicextensions   :="mp3,wav,aac,flac,aif,ogg"
picturesextensions:="jpg,bmp,png"
;- 
;---------------------
RSSINI=%A_scriptdir%\%name1%_RSSINI.txt
ifnotexist,%rssini%
    {
	xxca:="https://mediandr-a.akamaihd.net/download/podcasts/extradrei196/TV-20210108-1424-4800.hi.mp4"
    IniWrite,%xxca%  , %rssini%  ,A1   , KEY1
	Iniwrite,00:00:10, %rssini%  ,A2   , KEY1
    }
LastPlayedTEXT:=a_scriptdir . "\" . name1 . "_LastPlayed.txt"	
;--------------------------------------------------

;------- PICTURES for RANDOM-read ---------------------------
countP:=0
Loop, %FDPictures%\*.*,,1
{
if A_LoopFileExt in %picturesextensions%
  {
  countP++
  list_%countp% = %A_LoopFileShortPath%
  name_%countp% = %A_LoopFileName%
  }
}
gosub,randomtest1
;------------------------------------------------
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
ComObjError(false)
whr.Silent := True    ;- script failure = off
whr.SetTimeouts(500,500,500,500)
;-------------------------------------------------

x:=(wa*.1)/xx,y:=(ha*8.1)/xx,w:=(wa*15.7)/xx,h:=(ha*74)/xx
Gui,2:Add, ListView,backgroundBlack cGray  x%x% y%y% h%h% w%w% +hscroll +altsubmit gLW1 vLV1 , NAME|PATH|TIME
T1:=(wa*14.7)/xx,T2:=(wa*0)/xx,T3:=(wa*0)/xx
LV_ModifyCol(1,T1),LV_ModifyCol(2,T2),LV_ModifyCol(3,T3)
;-
x:=(wa*16)/xx ,y:=(ha*1)/xx,w:=(wa*82)/xx,h:=(ha*80)/xx
Gui,2:Add,ActiveX, x%x% y%y% w%w% h%h% vVlcx, VideoLAN.VLCPlugin.2
;------------------------------------------------------------
;--- lines down ---
x:=(wa*8)/xx ,y:=(ha*84)/xx,w:=(wa*80)/xx,h:=(ha*2)/xx
Gui,2:Add, Progress,  x%x%  y%y% w%w% h%h% vPRBAR backgroundGray range0-100 Disabled
Gui,2:Add, Text, x%x% y%y% w%w% h%h% gPrBar1 ,
x:=(wa*.2)/xx ,y:=(ha*84)/xx,w:=(wa*2)/xx,
Gui,2:Add,Text,       x%x%    y%y% w%w%    vT1 cYellow   ;- procent
x:=(wa*3)/xx ,y:=(ha*84)/xx,w:=(wa*4.2)/xx,
Gui,2:Add,Edit,       x%x%   y%y% w%w%     vT2 cYellow   ;- played time actual
x:=(wa*88.5)/xx ,y:=(ha*84)/xx,w:=(wa*4.2)/xx,
Gui,2:Add,Edit,       x%x% y%y% w%w%       vT3 cYellow   ;- total lenght from video
x:=(wa*93)/xx ,y:=(ha*84)/xx,w:=(wa*6)/xx,
Gui,2:Add,Text,       x%x% y%y% w%w%       vT5 cYellow   ;- vlc state playing paused
;------------
;--- buttons left top ----
;--------------------------

x:=(wa*.1)/xx ,y:=(ha*.5)/xx,w:=(wa*5)/xx,h:=(ha*2.3)/xx
Gui,2:add, Button  , x%x%   y%y%  w%w% h%h%   gMUSIC,MUSIC

x:=(wa*5.2)/xx ,y:=(ha*.5)/xx,w:=(wa*5)/xx,h:=(ha*2.3)/xx
Gui,2:add, Button  , x%x%   y%y%  w%w% h%h%   gVIDEO,VIDEO

x:=(wa*10.4)/xx ,y:=(ha*.5)/xx,w:=(wa*5)/xx,h:=(ha*2.3)/xx
Gui,2:add, Button  , x%x%   y%y%  w%w% h%h%   gExtra_3,Extra3

;-------- 2nd lines down ------------
x:=(wa*.1)/xx ,y:=(ha*87)/xx,w:=(wa*5)/xx,h:=(ha*2.3)/xx
Gui,2:add, Button  , x%x%   y%y%  w%w% h%h%   gSnapshot vSnapshot1, SNAPSHOT
;------------------------------------
x:=(wa*13)/xx,y:=(ha*87)/xx,w:=(wa*4.5)/xx,h:=(ha*2.3)/xx
Gui,2:add,Button   , x%x%   y%y%  w%w% h%h%  vLastPLAY gLastini,PLAY_NEW
;----------------------------
x:=(wa*18)/xx,y:=(ha*87)/xx,w:=(wa*3.5)/xx,h:=(ha*2.3)/xx
Gui,2:add,Button   , x%x%   y%y%  w%w% h%h%  vSTOP11 gSTOP,STOP
;----------------------------
a5xx=00:00:10   ;- Jump Back
a6xx=00:00:20   ;- Jump Forward
a7xx=00:02:25   ;- GoTo Seek
;----------------------------
Gui,2:Font,  S14 cGray ,Lucida Console
x:=(wa*40)/xx,y:=(ha*87)/xx,w:=(wa*5)/xx,h:=(ha*2.3)/xx
Gui,2:Add,Edit,cGray right  x%x%  y%y%    w%w%   h%h%   vJumpB,%a5xx%        ;-- Jump backward
;----------------------------
x:=(wa*40)/xx,y:=(ha*90)/xx,w:=(wa*5)/xx,h:=(ha*2.3)/xx
Gui,2:Add,Button,           x%x%  y%y%    w%w%   h%h%   gGoto1B   vGoto1B2   ,<SKIP
;----------------------------
x:=(wa*46)/xx,y:=(ha*87)/xx,w:=(wa*5)/xx,h:=(ha*2.3)/xx
Gui,2:Add,Edit,cGray right  x%x%  y%y%    w%w%   h%h%   vJumpF,%a6xx%        ;-- Jump forward
;----------------------------
x:=(wa*46)/xx,y:=(ha*90)/xx,w:=(wa*5)/xx,h:=(ha*2.3)/xx
Gui,2:Add,Button,           x%x%  y%y%    w%w%   h%h%   gGoto1F   vGoto1F2   ,SKIP>
;----------------------------
x:=(wa*52)/xx,y:=(ha*87)/xx,w:=(wa*5)/xx,h:=(ha*2.3)/xx
Gui,2:Add,Edit,cGray right  x%x%  y%y%    w%w%   h%h%   vGotox,%a7xx%        ;-- GotoX
;----------------------------
x:=(wa*52)/xx,y:=(ha*90)/xx,w:=(wa*5)/xx,h:=(ha*2.3)/xx
Gui,2:Add,Button,           x%x%  y%y%    w%w%   h%h%   gGoto1X   vGoto1X2   ,GotoX
;----------------------------
Gui,2:Font,  S11 cGray ,Lucida Console
x:=(wa*.1)/xx,y:=(ha*90)/xx,w:=(wa*39)/xx
Gui,2:add, Edit    , x%x%    y%y% w%w% cGray readonly vTxt1                  ;- show URL
;----------------------------
Gui,2:Add,Text,x0 y0 w0 h0 vEmptyText,
;----------------------------------------
w:=(wa*99.9)/xx,h:=(ha*93)/xx
Gui,2: Show,x0 y0 w%w% h%h%,%name1%   OS=%a_osversion% | AHK=%a_ahkversion% | %a_ostype% | 64bit=%a_is64bitos% | %wa%*%ha% | %a_username%=%a_isadmin% | %a_computername%
;------------------------------------
settimer,aas1,500
settimer,aas1,off
GuiControl,2:Disable,Snapshot1
GuiControl,2: Focus,EmptyText
sleep,500
return
;-----------------------------------------------------------------------------------------------------
2Guiclose:
Gui,2:submit,nohide
sleep,200
IniWrite,%T2%, %rssini% , A2 , Key1
;IniRead, C2a, %rssini% , A1 , Key1
;Fileappend,%c2a%`;%t2%`r`n,%LastPlayedTEXT%,utf-8
sleep,200  
exitapp
;----------------------------------------

;-- used ESCAPE -------------------------
aabb:
Gui,2:submit,nohide
ay:=vlcx.input.state
WinGet, IsMin, MinMax, % "ahk_id " uid
if (IsMin = -1)
 {
 WinRestore, % "ahk_id " uid
 if winexist(name1)
   Hotkey,SPACE,pause1,ON
 Guicontrolget,T5
 if (ay=4) 
   gosub,pause1  
 }
else
 {
 Winminimize 
 if winexist(name1)
   Hotkey,SPACE,pause1,OFF
  if (ay=3) 
   gosub,pause1  
 }
return
;-----------------------------------------
LASTINI:
Gui,2:submit,nohide
if winactive(name1)
  Hotkey,SPACE,pause1,ON
IniRead, C2, %rssini% , A1 , Key1
if C2<>
  {
  Guicontrol,2:,txt1,%C2%
  gosub,VideoAudioPLAY
  }
else
  msgbox, 262208, ,Error C2=%c2%
return

;======================================
VideoAudioPLAY:
Gui,2:submit,nohide
gosub,checkc2

if (checkvar="OK")
{
   vlcx.playlist.stop()
   vlcx.playlist.items.clear()
   vlcx.playlist.add(C2,"","""""")
   vlcx.playlist.next()
   settimer,aas1,on
}
else
msgbox, 262144, ,Not exist =`n%c2%   
return
;======================================

;-----------------------------------------

Playfile:
Gui,4:destroy
Gui,2:submit,nohide
gosub,checkc2

if (checkvar="OK")
{
vlcx.playlist.stop()
vlcx.playlist.items.clear()
vlcx.playlist.add(C2,"","""""")
vlcx.playlist.next()
settimer,aas1,on
gosub,clearall
if ext in %musicextensions%
  gosub,ChildPicture
}
else
  msgbox, 262144,NOT FOUND ,Not exist=`n%c2%  
return
;----------------------------------------

;============= CHECK C2 =============================
CheckC2:
if C2 contains file:///
{
stringreplace,c2a,c2,file:///,,all
Guicontrol,2:,txt1,%C2%
ifexist,%c2a%
 checkvar=OK
else
 checkvar=NOK
}

if C2 contains http
 { 
 checkvar=OK
 Guicontrol,2:,txt1,%C2%
 }
return
;----------------------------------------------------


;------------------- CHILDNEW for picture -----------
ChildPicture:
Gui,4:destroy
Gui,2:submit,nohide
Gui,4:Default
Gui,4: -DPIScale
Gui,4: Color,Black,black
Gui,4: +Parent2 -Sysmenu -caption
imgw:=0,imgh:=0
if hBitmap := GetThumbnailOrIcon(C2,0,0)
   {
   aa:="HBITMAP:" . GetThumbnailOrIcon(C2,300,300)
   }
else
   {
   gosub,randomtest2
   imgSize(ShowPic,imgw,imgh)
   aa:=ShowPic
   sleep,100
   }
;----------------------------
px:=(wa*4)/xx,x:=(wa*0)/xx,y:=(ha*0)/xx,w:=(wa*60)/xx,h:=(ha*80)/xx
if (imgw>imgh)
  Gui,4: Add, Pic,x%x% y%y% w%w%  h-1, %aa%
else if (imgh>imgw)
  Gui,4: Add, Pic,x%px% y%y% h%h% w-1, %aa%
else
  Gui,4: Add, Pic,x%x% y%y% w%w%  h-1, %aa%  
x:=(wa*17)/xx,y:=(ha*1)/xx,w:=(wa*80)/xx,h:=(ha*80)/xx
Gui,4: Show,x%x% y%y% w%w% h%h% , Child_2
return
;---------------------------------------

;--------------- LISTVIEW -------------
LW1:
Gui,2:Submit,nohide
Gui,2:ListView, LV1
LV_GetText(C1,A_EventInfo,1)
LV_GetText(C2,A_EventInfo,2)
LV_GetText(C3,A_EventInfo,3)
  RN:=LV_GetNext("C")
  RF:=LV_GetNext("F")
  GC:=LV_GetCount()
if (A_GuiEvent = "Normal")
 {
 if (rn=0)
    return
 ;msgbox, 262208,,C1=%c1%`nC2=%c2%
 Guicontrol,2:,txt1,%C2%
 SplitPath,C2, name, dir, ext, name_no_ext, drive
 C2=file:///%c2%
 IniWrite,%C2%, %rssini% ,A1   , KEY1
 gosub,playfile
 return
 }  
;-------------------------------------------------------------------
if A_GuiEvent = Rightclick
 {
 ;msgbox, 262208,,C1=%c1%`nC2=%c2%
 gosub,stop
 try
   run,%c2%
 }
Return
;================== END  LISTVIEW ===============================================
MUSIC:
Gui,2:submit,nohide
elf:="",lastfiles:=0
LV_Delete()
;---
I:=0
  Loop, Files,%FDMusic%\*.*,FDR
    {
    SplitPath,a_loopfilefullpath, name, dir, ext, name_no_ext, drive
    if ext in %musicextensions%
	  elf .= name . "              " . dlm . a_loopfilefullpath . "`r`n"
    }
for each, Line in StrSplit(elf, "`n", "`r")
{
if line=
  continue
Columns := StrSplit(Line,dlm)
LV_Add("",Columns*)
}
if elf=
  msgbox, 262144, ,PATH NOT FOUND =`n %fdmusic%
elf:="",I:=0
return
;----------------------------------------------
;---------- VIDEO -----------------------------
VIDEO:
Gui,2:submit,nohide
elf:="",lastfiles:=0
LV_Delete()
;---
I:=0
  Loop, Files,%FDVideo%\*.*,FDR
    {
    SplitPath,a_loopfilefullpath, name, dir, ext, name_no_ext, drive
    if ext in %videoextensions%
	  elf .= name . "         " . dlm . a_loopfilefullpath . "`r`n"
    }
for each, Line in StrSplit(elf, "`n", "`r")
{
if line=
  continue
Columns := StrSplit(Line,dlm)
LV_Add("",Columns*)
}
if elf=
  msgbox, 262144, ,PATH NOT FOUND =`n %FDVideo%
elf:="",I:=0
return
;----------------------------------------------
;=============================================================================  
  
;-----------  STOP ----------------------
STOP:
Gui,2:submit,nohide
if winexist(name1)
  Hotkey,SPACE,pause1,OFF
Guicontrolget,T2
settimer,aas1,off
GuiControl,2:Disable,Snapshot1
vlcx.playlist.stop()
vlcx.playlist.items.clear()
GuiControl,2:Text,T5,Stopped
IniWrite,%T2%, %rssini% , A2 , Key1
gosub,clearall
return
;------------------------------------------------------
;========== CLEAR ===================
clearall:
  GuiControl,2:Text,T1,
  GuiControl,2:Text,T2,
  GuiControl,2:Text,T3,
  Guicontrol,2:text,T5
  Guicontrol,2:text,prbar
  GuiControl,2:,PRBAR,0
  GuiControl,2:Text,Procentx   ,0`%
return
;-------------------------------------
;-------------------------------------
Prbar1:
gui,2:submit,nohide
vlcx.playlist.items.clear()
gosub,checkx
if (acc=0 or bcx=0)
   return
MouseGetPos,xpos
x100:=(wa*80)/xx
afc:=(wa*.2734375)/xx
procent  :=round((100*xpos)/x100)-afc
calctime :=((bc*procent)/100)
;msgbox,CALC=%calctime%`nLenght=%bcx%`nNow=%acc%
vlcx.input.time :=(calctime)
return
;---------------------------------
;------------------
#IfWinActive ahk_class AutoHotkeyGUI ahk_exe AutoHotkey.exe
~left::
Goto1B:
vlcx.playlist.items.clear()   ;--(?)
acx:=vlcx.input.time
guicontrolget,jumpb
varxx=%jumpb%
gosub,gosubtimecalc
vlcx.input.time :=(-total+acx)
return
;------------------
~right::
Goto1F:
vlcx.playlist.items.clear()   ;--(?)
acx:=vlcx.input.time
guicontrolget,jumpf
varxx=%jumpf%
gosub,gosubtimecalc
endtotal:=(total+acx)
if (endtotal>=bc)
   endtotal:=(bc-10000)        ;- goto endtotal minus 10 sec
vlcx.input.time :=(endtotal)
return
#IfWinActive
;------------------
Goto1X:
gui,2:submit,nohide
vlcx.playlist.items.clear()   ;--(?)
gosub,checkx
if (acc=0 or bcx=0)
   return
guicontrolget,gotoX
varxx=%gotox%
total:=0
gosub,gosubtimecalc
endtotal:=(total)
if (endtotal>bc)
   endtotal:=(bc-10000)       ;- goto endtotal minus 10 sec
vlcx.input.time :=(endtotal)
return
;========== VLC functions ============================
;-------- pause / PLAY --------------
pause1:
gui,2:submit,nohide
vlcx.playlist.items.clear()   ;--(?)
vlcx.playlist.togglePause()
return
;------- check ----------
checkx:
bc:=vlcx.input.length
ac:=vlcx.input.time
acc:=(ac//1000)
bcx:=(bc//1000)
return
;------------------
SNAPSHOT:
;- rename saved picture bmp to png ( is in a_scriptdir )
ifexist,%vlc1%
  vlcx.video.takeSnapshot()
return
;---------------------------------------------
;=============================================
;------------------------------- EXTRA-3 german satire ----------------------------------------
Extra_3:
Gui,2:submit,nohide
gosub,clearall
GuiControl,2:Disable,download1
GuiControl,2:Disable,Snapshot1
C2:=""
url:="https://www.ndr.de/fernsehen/sendungen/extra_3/video-podcast/index.xml"
whr.Open("GET",URL, true)
whr.Send()    ; Using 'true' above and the call below allows the script to remain responsive.
whr.WaitForResponse()
H := whr.ResponseText  ; haystack
;------------------------
B=<enclosure url="
E="
C2:=xStr(H,,B,E)
Guicontrol,2:,txt1,%C2%
Gui,4:destroy
if C2<>
  {
  Guicontrol,2:,txt1,%C2%
  IniWrite,%C2%, %rssini% ,A1   , KEY1
  gosub,VideoAudioPLAY
  }
else
  msgbox, 262208, ,Error read URL
return
;=========== settimer progressbar ==================
aas1:
gui,2:submit,nohide
ay:=vlcx.input.state
if (ay=6)
   {
   GuiControl,2:,PRBAR,100
   GuiControl,2:Text,Procentx   ,100`%
   GuiControl,2:Text,T5,ENDed
   settimer,aas1,off
   if winexist(name1)
     Hotkey,SPACE,pause1,OFF
   return
   }
if (ay=0)
   cy=Idle
if (ay=1)
   cy=Opening
if (ay=2)
   cy=Buffering
if (ay=3)
   cy=Playing
if (ay=4)
   cy=Paused
if (ay=5)
   cy=Stopped
if (ay=7)
   cy=Error

if winactive(name1)
  Hotkey,SPACE,pause1,ON
bc:=vlcx.input.length
ac:=vlcx.input.time
acc:=(ac//1000)
bcx:=(bc//1000)
if (acc=0 or bcx=0)
   return
;msgbox, 262208, ,acc=%acc%`nbcx=%bcx% , 1
SetFormat, float, 02
hours1   := (acc//3600)
minutes1 := (acc - hours1 * 3600)// 60
seconds1 := (acc - hours1 * 3600 - minutes1 * 60)
hours1  +=0.00
minutes1+=0.00
seconds1+=0.00
acc=%hours1%:%minutes1%:%seconds1%
;------- played-time ---------------
hours   := (bcx//3600)
minutes := (bcx - hours * 3600)// 60
seconds := (bcx - hours * 3600 - minutes * 60)
hours  +=0.00
minutes+=0.00
seconds+=0.00
bcx=%hours%:%minutes%:%seconds%
;----- total-time ----------------
GuiControl,2:Text,T5,%cy%
    RES1:=Round((100*AC)/BC)
    GuiControl,2:,PRBAR ,%res1%
GuiControl,2:Text,T1    ,%res1%`%   ;- procent
GuiControl,2:Text,T2    ,%acc%      ;- PlayedTime
GuiControl,2:Text,T3    ,%bcx%      ;- Lenght
if (CY="Paused") or (CY="Playing")
  GuiControl,2:Enable,Snapshot1
return
;===============  timecalc ===========
gosubtimecalc:
total:=0
y1=
y2=
y3=
  stringsplit,Y,varxx,`:
  if y3<>
  {
  hours:=(y1*60*60)*1000
  minutes:=(y2*60)*1000
  seconds:=(y3*1000)
  total:=(hours+minutes+seconds)
  }
  if (y3="" and y2<>"")
  {
  minutes:=(y1*60)*1000
  seconds:=(y2*1000)
  total:=(minutes+seconds)
  }
  if (y3="" and y2="")
     total:=(varxx*1000)
return
;======================================
;----------- for picture -------------------------------------
Randomtest1:          ;- run once a list from random numbers
;- Lotto / from user Laszlo
MIN:= 1
MAX:= countp     ;- Total pictures
N  := countp
i:=0, ex11:=""
Loop %N%
{
  i := A_Index
  loop
  {
    Random R, %MIN%, %MAX%     ; R = random number
    j := Index_%R%             ; get value from Indexes
    If j is number
      If j between 1 and % i - 1
        If (R_%j% = R)
          continue             ; repetition found, try again
    Index_%R% := i             ; store index
    R_%i% := R                 ; store in R_1, R_2...
	ff:=R_%i%
	ex11 .= ff . ","
    break                      ; different number
  }
}
return
;----------------------------------------------------------------
Randomtest2:
ck += 1
loop,parse,ex11,`,
 {
 x:=a_loopfield
 if (ck=a_index)
   {
   ShowPic := list_%x%
   NamePic := name_%x%
   break
   }
 }
;msgbox,Total-Pictures=%countp%`nLoop=%ck%`nRandom-Number=%x%
if (ck=countp)
 ck:=0
return 
;----------------------------------------------------------------
;----------------------------------------------------------------
imgSize(img, ByRef width , ByRef height) { ; Get image's dimensions
 If FileExist(img) {
  GUI,3: Add, Picture, hwndpic, %img%
  ControlGetPos,,, width, height,, ahk_id %pic%
  Gui,3: Destroy
 } Else height := width := 0
}

;------------------------------------------------------------------

;=============== get MP3 Picture thumbnail/ICO ============================================
;-------------
GetThumbnailOrIcon(filePath, width, height := 0, iconOnly := false) {
   static IID_IShellItemImageFactory := "{BCC18B79-BA16-442F-80C4-8A59C30C463B}"
        , SIIGBF_BIGGERSIZEOK := 0x00000001
        , SIIGBF_ICONONLY     := 0x00000004
   
   VarSetCapacity(GUID, 16, 0)
   DllCall("Ole32\IIDFromString", "WStr", IID_IShellItemImageFactory, "Ptr", &GUID)
   hr := DllCall("Shell32\SHCreateItemFromParsingName", "WStr", filePath, "Ptr", 0, "Ptr", &GUID, "PtrP", IShellItemImageFactory)
   if (hr != 0)
      Return 0
   flag := SIIGBF_BIGGERSIZEOK, (iconOnly && flag |= SIIGBF_ICONONLY)
   ; IShellItemImageFactory::GetImage
   DllCall(NumGet(NumGet(IShellItemImageFactory+0) + A_PtrSize*3), "Ptr", IShellItemImageFactory, "Int64", height << 32 | width
                                                                                                , "Int", flag, "PtrP", hBitmap, "Int")
   ObjRelease(IShellItemImageFactory)
   Return hBitmap
}
;==========================================================================================

;-------- saved at Dienstag, 7. April 2020 16:34:11 SKAN --------------
;- xStr  for general text extraction and parsing XML  HTML 
;- https://www.autohotkey.com/boards/viewtopic.php?f=6&t=74050
xStr(ByRef H, C:=0, B:="", E:="",ByRef BO:=1, EO:="", BI:=1, EI:=1, BT:="", ET:="") {                           
Local L, LB, LE, P1, P2, Q, N:="", F:=0                 ; xStr v0.97 by SKAN on D1AL/D343 @ tiny.cc/xstr  
Return SubStr(H,!(ErrorLevel:=!((P1:=(L:=StrLen(H))?(LB:=StrLen(B))?(F:=InStr(H,B,C&1,BO,BI))?F+(BT=N?LB
:BT):0:(Q:=(BO=1&&BT>0?BT+1:BO>0?BO:L+BO))>1?Q:1:0)&&(P2:=P1?(LE:=StrLen(E))?(F:=InStr(H,E,C>>1,EO=N?(F
?F+LB:P1):EO,EI))?F+LE-(ET=N?LE:ET):0:EO=N?(ET>0?L-ET+1:L+1):P1+EO:0)>=P1))?P1:L+1,(BO:=Min(P2,L+1))-P1)  
}
;------------------------------------------------------------------
;======== END SCRIPT =======================================
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Re: Play video inside AHK GUI

24 Dec 2022, 16:37

Thanks garry. I'm looking for a solution without using an external application such as VideoLan. Perhaps there isn't one.
just me
Posts: 9555
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Play video inside AHK GUI

25 Dec 2022, 04:30

WMPlayer.OCX How to take control of your Media

To get the duration:

Code: Select all

;- not work = webm
Extensions := "mp4,flv,vob,mpg,mkv"

FileSelectFile, file, 2, D:\M_MEDIA\M_VIDEO, Select WMP Compatible File:%extensions%
If Errorlevel
   ExitApp
SplitPath,file, name, dir, ext, name_no_ext, drive
If Ext not In %Extensions%
{
   MsgBox, 262208, , Can't PLAY`n--------------`nExtension is not in %extensions% .
   ExitApp
}

;Gui, +LastFound +Resize
Gui, Margin, 25, 25
Gui, Color,Black
Gui, Color,ControlColor, Black
Gui, Add, ActiveX, w1400 h800 vWMP, WMPLayer.OCX
WMP.uiMode := "none"                         ; no WMP controls
WMP.stretchToFit := 1                        ; video is streched to the given activex range
WMP.enableContextMenu := 0                   ; no reaction to right click in the video field
Gui, Show, , Player GUI
Media := WMP.newMedia(File)                  ; create a new Media object
Duration := Media.getItemInfo("Duration")    ; get its duration
WMP.currentMedia := Media                    ; set the players 'currenMedia' object
WMP.controls.play                            ; play
MsgBox, 0, Playing, %File% (%Duration% seconds)
Return

GuiClose:
ExitApp
:xmas:
garry
Posts: 3790
Joined: 22 Dec 2013, 12:50

Re: Play video inside AHK GUI

25 Dec 2022, 13:02

@just me thank you for solution, maybe can need some controls > forward / back , time played ...
there was a failure in my old script

Code: Select all

;Gui, Color,Black
;Gui, Color,ControlColor, Black  ;- wrong
;-
;replace these with :
Gui, Color,Black,Black
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Re: Play video inside AHK GUI

29 Dec 2022, 22:47

Thanks very much garry for the correction and just me for the duration code and link. I've been able to play video in a gui now on all the computers I had problems with. Being able to avoid using an external media player is very useful but are activex controls likely to remain in the future? Thanks again.
garry
Posts: 3790
Joined: 22 Dec 2013, 12:50

Re: Play video inside AHK GUI

30 Dec 2022, 03:05

WMplayer.exe is Windows Media Player , I like to use often standalone programs with commandline parameters combined with ahk , e.g. Videolan vlc.exe (for every formats audio,video ) or Irfanview ( pictures resize,cut ...) ...
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Re: Play video inside AHK GUI

30 Dec 2022, 03:50

Thanks for the clarification, garry. Is it safe to assume that using windows media player will always work unless a user has deliberately removed it? I've been using mpc-be to play video but I can't assume someone will have that. It seems easier to control windows media player using the controls just me linked to.
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Re: Play video inside AHK GUI - Start Issue

20 Jan 2023, 00:53

This is the basic code I'm using to play a video inside a GUI which is part of a larger script:

Code: Select all

Gui, Vid:New, +alwaysontop -Caption +owndialogs +HwndVNP -dpiscale +E0x02000000 +E0x00080000, Video Now Playing
Gui, Add, ActiveX, x0 y0  w%_W% h%_H% vWMP, WMPLayer.OCX ;_W _H width and height of monitor 2

WMP.uiMode := "none"                         ; no WMP controls
WMP.stretchToFit := 1                        ; video is streched 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
Clip := WMP.newMedia(Now)                  ; create a new Media object
Dur:= Clip.getItemInfo("Duration")    ; get its duration

WMP.currentMedia := Clip                    ; set the players 'currenMedia' object
WMP.controls.play                            ; play
sleep 1000
Gui, Vid:show,noactivate x%X_% y%Y_% h%_H% w%_W% ;X_ Y_ top left hand corner of monitor 2

Groupadd, Wise, ahk_id %VNP%
WinGet, vPid, pid, ahk_id %Wise%
SoundVol(Zol) 
Winactivate, ahk_id %media%	
Very occasionally a video has problems loading and the first couple of seconds have a black flicker. Could this be caused by +E0x02000000 +E0x00080000? Are there any checks I can do to make sure a video is loaded correctly before it starts? Thanks.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Kellyzkorner_NJ and 161 guests