xseekx Posted March 27, 2015 Share Posted March 27, 2015 Hi. I'm new here! I have created a simple script to automate the process of recording an IP stream in VLC media player and it works! Now I have to find out how to stop the recording after the specified ending time. I am using 'Windows task scheduler' to run the script on a schedule. The script opens VLC and executes the default recording hotkey (+r). I want to find a way to re-execute (send ("+r")), about a second before the task ends in Windows task scheduler. So essentially I will be automating the process of recording in VLC media player on a schedule in Windows 7. Like I said I'm new here! I’m open to suggestions instead of using Windows task scheduler, or maybe there is a simple few lines of code I can add? My code. http://imgur.com/gallery/7VumOaw/new Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted March 27, 2015 Share Posted March 27, 2015 (edited) VLC has cmd backend so its very scriptable. I guess you know when the stream is ending so staying along the same lines of what you are doing now I don't see why you would not just call another script to press the keys to stop recording and then close VLC. Something like a WinActivate() Send() ProcessClose() Edited March 27, 2015 by ViciousXUSMC Link to comment Share on other sites More sharing options...
xseekx Posted March 28, 2015 Author Share Posted March 28, 2015 (edited) I have edited my code to have a GUI which will allow me to enter a start time an stop time in (HH:MM). What I'm trying to do: When I start the script, A GUI will start. I then enter the start hour, and the start minute of the recording. I will then enter the end hour and the end minute of the recording. I will the click a the save button which will load the times into the variables. My 'if statement' should then check to see if the time to start recording is the current time, or a future time. If it is a future time it should start recording at that time, and also end at the time I have specified in the GUI. My problem: In the GUI, If I enter a future time to start the recording, it seems that the code 'If @HOUR = $theStartHour And @MIN = $theStartMinute Then' at line# 64 does not work. But if I enter the current time into the GUI , VLC with start, and keep on recording and stopping. So I believe I should be using some other loop besides a 'do ... until'? I'm just not sure how to do something until a specified time in a loop, without keep on executing until the time is reached My code. expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Date.au3> #Region ### START Koda GUI section ### Form=c:\users\eric\desktop\stream tut\myform.kxf Global $myForm = GUICreate("myForm", 615, 438, -1, -1) $Label1 = GUICtrlCreateLabel("Start Time", 272, 24, 52, 17) GUICtrlSetBkColor(-1, 0x00FF00) $sHour = GUICtrlCreateLabel("Start Hour", 208, 72, 52, 17) GUICtrlSetBkColor(-1, 0xA6CAF0) Global $HourStart = GUICtrlCreateInput("", 272, 72, 73, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER)) $sMin = GUICtrlCreateLabel("Start Minute", 208, 112, 61, 17) GUICtrlSetBkColor(-1, 0xA6CAF0) Global $MinuteStart = GUICtrlCreateInput("", 272, 112, 73, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER)) GUICtrlCreateLabel("End Time", 277, 155, 49, 17) GUICtrlSetBkColor(-1, 0xFF0000) $ehour = GUICtrlCreateLabel("End Hour", 213, 187, 49, 17) GUICtrlSetBkColor(-1, 0xA6CAF0) $eMin = GUICtrlCreateLabel("End Minute", 210, 220, 58, 17) GUICtrlSetBkColor(-1, 0xA6CAF0) Global $HourEnd = GUICtrlCreateInput("", 280, 184, 65, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER)) Global $MinuteEnd = GUICtrlCreateInput("", 280, 216, 65, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER)) Global $saveBtn = GUICtrlCreateButton("Save", 272, 264, 75, 25) Global $cancelBtn = GUICtrlCreateButton("Cancel", 272, 296, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1;the infinite loop to keep the script alive $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit ;If the 'Save' button is clicked, then execute the following Case $saveBtn ;START TIME ;Get the start hour from user input $startHourInput = GUICtrlRead($HourStart) ;Set the hour to the user input $theStartHour = $startHourInput ;Get the start minute from user input $startMinuteInput = GUICtrlRead($MinuteStart) ;Set the minute to the user input $theStartMinute = $startMinuteInput ;END TIME ;Get the end hour $endHourInput = GUICtrlRead($HourEnd) $theEndHour = $endHourInput ;Get the end minute $endMinuteInput = GUICtrlRead($MinuteEnd) $theEndMinute = $endMinuteInput ;NOT WORKING CORRECTLY ;When it is the specified hour If @HOUR = $theStartHour And @MIN = $theStartMinute Then Do ;Start Recording startRecord() ;until the end time specified in the GUI Until @HOUR = $theEndHour And @MIN = $theEndMinute ;Otherwise the time has not been reached ElseIf Not (@HOUR = $theStartHour) And Not (@MIN = $theStartMinute) Then ;The Sleep() function uses miliseconds, so I will have to convert time ;minutes = hours x 60 $hourNum = $theStartHour $minuteNum = $theStartMinute $minutesCalc = ($theStartHour * 60) + $minuteNum ;milliseconds = minutes x 60,000 $milli = ($minutesCalc) * 60000 ;Sleep until the start time Sleep($milli) ;Then start recording startRecord() ;MsgBox(0, "", "The time is reached") EndIf Case $cancelBtn Exit EndSwitch WEnd Func startRecord() ;Open the stream file, which will open up VLC by default ShellExecute("E:\Eric\Documents\dbStream.m3u") ;Wait 7 secs for VLC stream to start Local $hWnd = WinWait("[CLASS:VLC media player]", "", 7) ;Focus on the window WinActivate($hWnd) ;Start recording Send("+r") EndFunc ;==>startRecord Func endRecord() ;Stop recording Send("+r") ;Close The VLC window WinClose("VLC media player") EndFunc ;==>endRecord Edited March 28, 2015 by xseekx Link to comment Share on other sites More sharing options...
xseekx Posted March 28, 2015 Author Share Posted March 28, 2015 (edited) I have now changed my code to use a 'while loop', instead of a 'do loop', but I am having the same problem. expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Date.au3> #Region ### START Koda GUI section ### Form=c:\users\eric\desktop\stream tut\myform.kxf Global $myForm = GUICreate("myForm", 615, 438, -1, -1) $Label1 = GUICtrlCreateLabel("Start Time", 272, 24, 52, 17) GUICtrlSetBkColor(-1, 0x00FF00) $sHour = GUICtrlCreateLabel("Start Hour", 208, 72, 52, 17) GUICtrlSetBkColor(-1, 0xA6CAF0) Global $HourStart = GUICtrlCreateInput("", 272, 72, 73, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER)) $sMin = GUICtrlCreateLabel("Start Minute", 208, 112, 61, 17) GUICtrlSetBkColor(-1, 0xA6CAF0) Global $MinuteStart = GUICtrlCreateInput("", 272, 112, 73, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER)) GUICtrlCreateLabel("End Time", 277, 155, 49, 17) GUICtrlSetBkColor(-1, 0xFF0000) $ehour = GUICtrlCreateLabel("End Hour", 213, 187, 49, 17) GUICtrlSetBkColor(-1, 0xA6CAF0) $eMin = GUICtrlCreateLabel("End Minute", 210, 220, 58, 17) GUICtrlSetBkColor(-1, 0xA6CAF0) Global $HourEnd = GUICtrlCreateInput("", 280, 184, 65, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER)) Global $MinuteEnd = GUICtrlCreateInput("", 280, 216, 65, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER)) Global $saveBtn = GUICtrlCreateButton("Save", 272, 264, 75, 25) Global $cancelBtn = GUICtrlCreateButton("Cancel", 272, 296, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1;the infinite loop to keep the script alive $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Break ;If the 'Save' button is clicked, then execute the following Case $saveBtn ;START TIME ;Get the start hour from user input $startHourInput = GUICtrlRead($HourStart) ;Set the hour to the user input $theStartHour = $startHourInput ;Get the start minute from user input $startMinuteInput = GUICtrlRead($MinuteStart) ;Set the minute to the user input $theStartMinute = $startMinuteInput ;END TIME ;Get the end hour $endHourInput = GUICtrlRead($HourEnd) $theEndHour = $endHourInput ;Get the end minute $endMinuteInput = GUICtrlRead($MinuteEnd) $theEndMinute = $endMinuteInput ;NOT WORKING CORRECTLY While (@HOUR = $theStartHour And @MIN = $theStartMinute) startRecord() If Not (@HOUR = $theStartHour) And Not (@MIN = $theStartMinute) Then ;The Sleep() function uses miliseconds, so I will have to convert time ;minutes = hours x 60 $hourNum = $theStartHour $minuteNum = $theStartMinute $minutesCalc = ($theStartHour * 60) + $minuteNum ;milliseconds = minutes x 60,000 $milli = ($minutesCalc) * 60000 ;Sleep until the start time Sleep($milli) ;Then start recording startRecord() ;MsgBox(0, "", "The time is reached") EndIf endRecord() WEnd EndSwitch WEnd Func startRecord() ;Open the stream file, which will open up VLC by default ShellExecute("E:\Eric\Documents\dbStream.m3u") ;Wait 7 secs for VLC stream to start Local $hWnd = WinWait("[CLASS:VLC media player]", "", 7) ;Focus on the window WinActivate($hWnd) ;Start recording Send("+r") EndFunc ;==>startRecord Func endRecord() ;Stop recording Send("+r") ;Close The VLC window WinClose("VLC media player") EndFunc ;==>endRecord I think that I am misunderstanding @HOUR, @MIN. I wonder if I have to keep checking the system time? By the way, this is the forum Koda forum that I will be using. http://imgur.com/gallery/xVbQTvN/new Edited March 28, 2015 by xseekx Link to comment Share on other sites More sharing options...
xseekx Posted March 28, 2015 Author Share Posted March 28, 2015 (edited) VLC has cmd backend so its very scriptable. I guess you know when the stream is ending so staying along the same lines of what you are doing now I don't see why you would not just call another script to press the keys to stop recording and then close VLC. Something like a WinActivate() Send() ProcessClose() I have tried doing a VBScript, but when I tried using 'AppActivate', in vbs I couldn't get the VLC window to focus, So I couldn't execute a hotkey, but I can focus using 'WinActivate' in Autoit script. Edited March 28, 2015 by xseekx Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted March 28, 2015 Share Posted March 28, 2015 Instead of going with current hour/time etc. I would probably try something like Take your End Time Subtract the Start time to get the Net Record Length. Fire off a TimerInit() to start a timer and then do a comparison. If NetRecordTime is Less Than or Equal To TimerDiff() Then ... https://www.autoitscript.com/autoit3/docs/functions/TimerDiff.htm https://www.autoitscript.com/autoit3/docs/functions/TimerInit.htm 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