MattyGibbard Posted May 25, 2008 Share Posted May 25, 2008 (edited) Hey guys and girls I am making something for my girlfriend in Autoit for her to open and look at. I just wanted to know if I could have a video in my GUI or in a child window. The video can change format so I can make it whatever format it needs to be in. I tried but it kept coming up with and error about a "Bad Image". I was using the GUIctrlcreateavi function and converting my video to .avi Can anyone help please? Here is my code: expandcollapse popup#include <GUIConstants.au3> #include <WindowsConstants.au3> #include <Sound.au3> $soundcheck = MSGbox (4, "Hello Amy", "Have you got your sound on?") If $soundcheck = 7 Then Msgbox (0,"Tut Tut", "Turn it on and restart this file") Exit Endif SoundPlay("data/1.mp3",0) GUICreate("The Girl Of My Dreams - Amy Cassells - Matt Gibbard", 800, 600) $images = GUICtrlCreateButton ("View Our Pics", 10, 30, 100) $exit = GUICtrlCreateButton ( "Exit", 10, 70, 100) Guictrlcreategroup ("Our Love Clock" , 50 , 100 , 600, 100) $Goingourdate = guictrlcreateinput ( "", 60,150,400) guictrlcreatelabel ("<-- Don't click this box, it will spaz up." ,465,155) ;-------------------------------------- GUISetState () While 1 $daycheck = @YDAY + 107 Guictrlsetdata ($goingourdate , "We Have Been Going Out For: " & $daycheck & " days, " & @Hour & " hours, " & @MIN & " mins, and " & @SEC & " seconds.") $msg = GUIGetMsg() Select ;-------------------------------------- ;Red X Case $msg = $GUI_EVENT_CLOSE Exitloop ;Red X Stop ;-------------------------------------- Case $msg = $images SplashImageOn ( "Amy Cassells", "data/1.jpg", 500,500) Sleep (5000) SplashOff() SplashImageOn ( "Amy Cassells", "data/2.jpg", 500,500) Sleep (5000) SplashOff() SplashImageOn ( "Amy Cassells", "data/3.jpg", 500,500) Sleep (5000) SplashOff() SplashImageOn ( "Amy Cassells", "data/4.jpg", 500,500) Sleep (5000) SplashOff() SplashImageOn ( "Amy Cassells", "data/5.jpg", 500,500) Sleep (5000) SplashOff() SplashTextOn ("Amy" , "I LOVE YOU X" ,200,50) Sleep (5000) SplashOff() Case $msg = $exit exit EndSelect Wend Thank You Edited May 25, 2008 by mattygibbard Link to comment Share on other sites More sharing options...
rawrr Posted May 26, 2008 Share Posted May 26, 2008 Where do you want the video? Link to comment Share on other sites More sharing options...
MattyGibbard Posted May 26, 2008 Author Share Posted May 26, 2008 Either in the GUI just playing from a click of a button. Or in a window that pop's up like a child GUI. Link to comment Share on other sites More sharing options...
LinuZ Posted May 26, 2008 Share Posted May 26, 2008 Aww cute I don't know how I could help but I could give you a suggestion; add your pictures on a FTP server and make the program download em and play them all, this way you could allways add pictures to the server without having to send her the .exe over and over again (since it seems for much persons as a problem to pack up a simple .ZIP file xD) Link to comment Share on other sites More sharing options...
smashly Posted May 26, 2008 Share Posted May 26, 2008 Hi, here's an example of adding an avi or mpg video to your gui. I've only tried it in WinXP SP2 with autoit v3.2.10.0 and v3.2.11.12 beta. (Vista OS may not work with it) You can read the Function comments at bottom of script to get an idea of how to use the video functionsexpandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Sound.au3> HotKeySet('!{ENTER}', 'FullScreen') ; Alt + Enter toggles fullscreen Opt("GuiOnEventMode",1) Global $vID, $Fullscreen $GUI = GUICreate("Video Control", 400, 335 , -1, -1, BitOr($WS_OVERLAPPEDWINDOW,$WS_CLIPCHILDREN)) GUISetOnEvent($GUI_EVENT_CLOSE , "Event") $Play = GUICtrlCreateButton("Play", 5, 305, 40, 25) GUICtrlSetOnEvent(-1 , "Event") GuiCtrlSetState(-1, $GUI_DISABLE) $Stop = GUICtrlCreateButton("Stop", 50, 305, 40, 25) GUICtrlSetOnEvent(-1 , "Event") GuiCtrlSetState(-1, $GUI_DISABLE) $Open = GUICtrlCreateButton("Load", 95, 305, 40, 25) GUICtrlSetOnEvent(-1 , "Event") GuiSetState(@SW_SHOW, $GUI) While 1 Sleep(100) WEnd Func Event() Switch @GUI_CtrlId Case $GUI_EVENT_CLOSE _SoundClose($vID) Exit Case $Play If _SoundStatus($vID) = "playing" Then _SoundPause($vID) GUICtrlSetData($Play, 'Play') ElseIf _SoundStatus($vID) = "paused" Then _SoundResume($vID) GUICtrlSetData($Play, 'Pause') ElseIf _SoundStatus($vID) = "stopped" Then _VidPlay($vID, 0) GUICtrlSetData($Play, 'Pause') EndIf Case $Stop If _SoundStatus($vID) = "playing" Then _SoundStop($vID) GUICtrlSetData($Play, 'Play') EndIf Case $Open $file = FileOpenDialog("OPEN","","Video (*.avi;*.mpg)") If @error <> 1 Then If _SoundStatus($vID) <> "" Then _SoundClose($vID) GUICtrlSetData($Play, 'Play') EndIf $vID = _VidOpen($file, "", $GUI, 0, 0, 400, 300) If $vID <> "" Then _VidPlay($vID, 0) GUICtrlSetData($Play, 'Pause') GuiCtrlSetState($Play, $GUI_ENABLE) GuiCtrlSetState($Stop, $GUI_ENABLE) EndIf EndIf EndSwitch EndFunc Func FullScreen() If $Fullscreen = 0 Then _VidPlay($vid, 1) $Fullscreen = 1 ElseIf $Fullscreen = 1 Then _VidPlay($vid, 0) $Fullscreen = 0 EndIf EndFunc ;=============================================================================== ; ; Function Name: _VidOpen($vFile, $vAlias, $guID, $vX1, $vY1, $vX2, $vY2) ; Description:: Opens a Video file as a control in a gui for use with other _Vid/_Sound functions ; Parameter(s): $vFile - The full path to video file (spaces in path/file name is fine) ; $vAlias - a name such as sound1 (must contain no spaces), use "" and it is randomly generated ; $guID - The GUI handle that the video control will be displayed in ; $vX1 - Left position in the GUI (set as 0 for left edge of GUI) ; $vY1 - Top position in the GUI (set as 0 for Top edge of GUI, flush to Title bar if one exists) ; $vX2 - Width of the video ; $vY2 - Height of the video ; Requirement(s): AutoIt 3.2 ++ ; Return Value(s): string(the alias video id for use in other _Vid/_Sound functions) - Success ; 0 - Failure ; @extended <> 0 - open failed ; @error = 2 - File doesn't exist ; @error = 3 - alias contains whitespace ; @error = 4 - GUI handle is not valid ; @error = 5 - Failed to render video to GUI ; @error = 6 - Failed to place video at the deignated location in GUI ; Author(s): smashly (modified from RazorM sound udf for video open) ; ; ;=============================================================================== ; Func _VidOpen($vFile, $vAlias, $guID, $vX1, $vY1, $vX2, $vY2) ;Declare variables Local $vID, $iCurrentPos, $gId, $vRet, $vWin, $vLoc ;check for file If Not FileExists($vFile) Then Return SetError(2, 0, 0) ;search for whitespace by character For $iCurrentPos = 1 To StringLen($vAlias) If StringIsSpace(StringMid($vAlias, $iCurrentPos, 1)) Then Return SetError(3, 0, 0) Next ;create random alias if one is not supplied If $vAlias = "" Then $vID = RandomStr(10) Else $vID = $vAlias EndIf ;check and translate the GUI handle into a ASCII numeric equivalent If StringLeft($guID, 2) = '0x' And StringIsXDigit(StringTrimLeft($guID, 2)) = 1 Then $gId = Dec(StringTrimLeft($guID,2)) Else Return SetError(4, 0, 0) EndIf ;open video file in the GUI at desired location and size $vRet = mciSendString("open " & FileGetShortName($vFile) & " alias " & $vID) $vWin = mciSendString("window " & $vID & " handle " & $gId) If $vWin <> 0 Then mciSendString("close " & $vID) Return SetError(5, 0, 0) EndIf $vLoc = mciSendString("put " & $vID & " destination at " & $vX1 & " " & $vY1 & " " & $vX2 & " " & $vY2) If $vLoc <> 0 Then mciSendString("close " & $vID) Return SetError(6, 0, 0) EndIf Return SetError(0, $vRet, $vID) EndFunc ;==>_VidOpen ;=============================================================================== ; ; Function Name: _VidPlay($vID, $fScreen) ; Description:: Plays a Video from the current position (beginning is the default) ; Parameter(s): $vID - Video ID returned by _VidOpen ; $fScreen [Optional] - If set to 1 the will be played in FullScreen (no Gui or Controls displayed) ; - If set to 0 the video will play in the GUI as specified in _VidOpen ; - If omitted then 0 will be used (play in the GUI as specified in _VidOpen) ; Requirement(s): AutoIt 3.2 ++ ; Return Value(s): 1 - Success, 0 - Failure ; @error = 1 - play failed ; Author(s): smashly (modified from RazorM sound udf for video play) ; ;=============================================================================== ; Func _VidPlay($vID, $fScreen = 0) ;Declare variables Local $vRet ;if sound has finished, seek to start If _SoundPos($vID, 2) = _SoundLength($vID, 2) Then mciSendString("seek " & $vID & " to start") If $fScreen = 1 Then $vRet = mciSendString("play " & $vID & " fullscreen") Else $vRet = mciSendString("play " & $vID) EndIf ;return If $vRet = 0 Then Return 1 Else Return SetError(1, 0, 0) EndIf EndFunc ;==>_VidPlay If your avi video is an xvid, divx or similar then you may need to add a registry key for it to play back correctly. The registry key is posted below if you need it. (try without the reg entry first, if avi playback is screwy then use the reg key if needed): Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\MCI Extensions] "avi"="mpegvideo" Cheers Link to comment Share on other sites More sharing options...
GEOSoft Posted May 26, 2008 Share Posted May 26, 2008 There is some nice work in there @smashly. Congratulations. I just had another thought while I was reading the thread and I have not tried it yet. I'm thinking that another way to do video would be to write an html page that had the video embedded and then use _IE_CreateEmbedded() and call the html page. It's just a theoretical concept at this point but it could allow for things like nice borders around the video, banners or background changes and the video controls are available. Dale is really the expert but I'm pretty sure that it would work. I just don't have time to test it right now. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" 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