Jump to content

_fileListToArray() not generating specific lists and question about random


Recommended Posts

I need help with 2 things:

1) I need my script to generate a list of all the wmv files in the script directory. When I use:

Global $AviList = _FileListToArray(@ScriptDir) 
_ArrayDisplay($AviList)

I can see the array with all of the elements from the script directory however when I try to whittle down the list to just wmv files with this:

Global $AviList = _FileListToArray(@ScriptDir & "\" & "*.wmv") 
_ArrayDisplay($AviList)

I get nothing. How can I put only the wmv files in a directory in the array? Also I would like to call random files from the array and play them in mplayer2 which brings me to the next item I need help with.

2) I need my script to record the time between activity in the script and after 20 seconds begin to play the random wmv files from above. eg I need the script to wait until a video file is done playing and then start counting to 20 and then start randomly playing the files in the array. The trick is for the script to wait until any video files are done playing before calling the random video file section. Can I use WinWait make the script start counting after the video file is done playing?

Here's my code so far:

Global $AviList = _FileListToArray(@ScriptDir) 
Global $time = 10;sec
$timer = TimerInit()
$Form1 = GUICreate("Scan Barcode", 150, 22, 1, 1); creats a GUI window (Width, Height, Left, Top,)
$edit_field = GUICtrlCreateInput("", 0, 0, 148, 21); ( "text", left, top , width , height)

GUISetState()

; temp.txt is a file that has the encrypted file string stored in it
; barcode.ini is a file that is used as a temp file for storing the data

If FileExists(@ScriptDir & "\" & "barcode.ini") Then;deletes the temp file barcode.ini in case of a computer crash
   FileDelete(@ScriptDir & "\" & "barcode.ini")
EndIf

FileOpen("temp.ini", 0); calls the file temp.txt for reading later
; Check if file opened for writing OK
If $file = -1 Then
    MsgBox(0, "Error 101", "Cant find barcode.ini.")
    Exit
EndIf
$file = FileRead("temp.ini"); reads temp.txt and assigns the data to $file

    FileOpen("barcode.ini", 2);opens the file in write mode (it will create the file if it doesn't exist)
    $Decrypted_Data = _StringEncrypt (0 , $file, "1234"); decrypts the string "$file" - Tested
    FileWrite("barcode.ini", $Decrypted_Data); writes the data to barcode.ini
    FileClose("barcode.ini");closes the file
_ArrayDisplay($AviList)
While 1 
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
        FileClose(@ScriptDir & "\" & "barcode.ini")
        FileDelete(@ScriptDir & "\" & "barcode.ini")
        Exit
    Case $edit_field
           $user_input = GUICtrlRead($edit_field); sets $user_input to whatever was typed in the edit box
            If IniRead("barcode.ini", "AviCodes", $user_input, "no entry") = "no entry" Then
                MsgBox(16, "Code not found", "The Barcode you entered "&$user_input&" does not have a video.",2)
                WinActivate("Scan Barcode")
                GUICtrlSetData($edit_field, "");erases not successful input
            Else
                $video_file = (@ScriptDir & "\" & IniRead("barcode.ini", "AviCodes", $user_input, "no entry"))
                Run (@ProgramFilesDir & "\Windows Media Player\mplayer2.exe /play /fullscreen /close "&$video_file&"")
                Sleep (5000)
                WinActivate("Scan Barcode")
                GUICtrlSetData($edit_field, "");erases not successful input
            EndIf
EndSwitch
WEnd

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

I need help with 2 things:

1) I need my script to generate a list of all the wmv files in the script directory. When I use:

Global $AviList = _FileListToArray(@ScriptDir) 
_ArrayDisplay($AviList)

I can see the array with all of the elements from the script directory however when I try to whittle down the list to just wmv files with this:

Global $AviList = _FileListToArray(@ScriptDir & "\" & "*.wmv") 
_ArrayDisplay($AviList)

I get nothing. How can I put only the wmv files in a directory in the array? Also I would like to call random files from the array and play them in mplayer2 which brings me to the next item I need help with.

2) I need my script to record the time between activity in the script and after 20 seconds begin to play the random wmv files from above. eg I need the script to wait until a video file is done playing and then start counting to 20 and then start randomly playing the files in the array. The trick is for the script to wait until any video files are done playing before calling the random video file section. Can I use WinWait make the script start counting after the video file is done playing?

Here's my code so far:

Global $AviList = _FileListToArray(@ScriptDir) 
Global $time = 10;sec
$timer = TimerInit()
$Form1 = GUICreate("Scan Barcode", 150, 22, 1, 1); creats a GUI window (Width, Height, Left, Top,)
$edit_field = GUICtrlCreateInput("", 0, 0, 148, 21); ( "text", left, top , width , height)

GUISetState()

; temp.txt is a file that has the encrypted file string stored in it
; barcode.ini is a file that is used as a temp file for storing the data

If FileExists(@ScriptDir & "\" & "barcode.ini") Then;deletes the temp file barcode.ini in case of a computer crash
   FileDelete(@ScriptDir & "\" & "barcode.ini")
EndIf

FileOpen("temp.ini", 0); calls the file temp.txt for reading later
; Check if file opened for writing OK
If $file = -1 Then
    MsgBox(0, "Error 101", "Cant find barcode.ini.")
    Exit
EndIf
$file = FileRead("temp.ini"); reads temp.txt and assigns the data to $file

    FileOpen("barcode.ini", 2);opens the file in write mode (it will create the file if it doesn't exist)
    $Decrypted_Data = _StringEncrypt (0 , $file, "1234"); decrypts the string "$file" - Tested
    FileWrite("barcode.ini", $Decrypted_Data); writes the data to barcode.ini
    FileClose("barcode.ini");closes the file
_ArrayDisplay($AviList)
While 1 
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
        FileClose(@ScriptDir & "\" & "barcode.ini")
        FileDelete(@ScriptDir & "\" & "barcode.ini")
        Exit
    Case $edit_field
           $user_input = GUICtrlRead($edit_field); sets $user_input to whatever was typed in the edit box
            If IniRead("barcode.ini", "AviCodes", $user_input, "no entry") = "no entry" Then
                MsgBox(16, "Code not found", "The Barcode you entered "&$user_input&" does not have a video.",2)
                WinActivate("Scan Barcode")
                GUICtrlSetData($edit_field, "");erases not successful input
            Else
                $video_file = (@ScriptDir & "\" & IniRead("barcode.ini", "AviCodes", $user_input, "no entry"))
                Run (@ProgramFilesDir & "\Windows Media Player\mplayer2.exe /play /fullscreen /close "&$video_file&"")
                Sleep (5000)
                WinActivate("Scan Barcode")
                GUICtrlSetData($edit_field, "");erases not successful input
            EndIf
EndSwitch
WEnd
The first parameter in _FileListToArray is the folder. For a filter you add a second parameter.

Global $AviList = _FileListToArray(@ScriptDir,"*.wmv") 
_ArrayDisplay($AviList)

I haven't read your second piece of script so I've no help with that. (Too late now for me.)

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

While 1    
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
        FileClose(@ScriptDir & "\" & "barcode.ini")
        FileDelete(@ScriptDir & "\" & "barcode.ini")
        Exit
    Case $edit_field
           $user_input = GUICtrlRead($edit_field); sets $user_input to whatever was typed in the edit box
            If IniRead("barcode.ini", "AviCodes", $user_input, "no entry") = "no entry" Then
                MsgBox(16, "Code not found", "The Barcode you entered "&$user_input&" does not have a video.",2)
                WinActivate("Scan Barcode")
                GUICtrlSetData($edit_field, "");erases not successful input
            Else
                $video_file = (@ScriptDir & "\" & IniRead("barcode.ini", "AviCodes", $user_input, "no entry"))
                Run (@ProgramFilesDir & "\Windows Media Player\mplayer2.exe /play /fullscreen /close "&$video_file&"")
                Sleep (5000)
                $timer = TimerInit()    ;restart the timer
                WinActivate("Scan Barcode")
                GUICtrlSetData($edit_field, "");erases not successful input
            EndIf
    EndSwitch
    If TimerDiff($timer) > 20000 Then   ;if timer > 20 sec
        _PlayRandom()
    EndIf
WEnd

Func _PlayRandom()
    ;add code here to play random file from your $AviList
    ;and use RunWait for mplayer not Run as you did in this code
EndFunc

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

OK I did the following and it is playing random avi files after 20 seconds:

#Region;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=Barcode.exe
#EndRegion;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstants.au3>
#include <string.au3>
#Include <File.au3>
#Include <Array.au3>
Global $Paused
Global $file
Global $AviList = _FileListToArray(@ScriptDir,"*.wmv") 
Global $time = 10;sec
$timer = TimerInit()
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
$Form1 = GUICreate("Scan Barcode", 150, 22, 1, 1); creats a GUI window (Width, Height, Left, Top,)
$edit_field = GUICtrlCreateInput("", 0, 0, 148, 21); ( "text", left, top , width , height)
GUISetState()

; temp.txt is a file that has the encrypted file string stored in it
; barcode.ini is a file that is used as a temp file for storing the data

If FileExists(@ScriptDir & "\" & "barcode.ini") Then;deletes the temp file barcode.ini in case of a computer crash
   FileDelete(@ScriptDir & "\" & "barcode.ini")
EndIf

FileOpen("temp.ini", 0); calls the file temp.txt for reading later
; Check if file opened for writing OK
If $file = -1 Then
    MsgBox(0, "Error 101", "Cant find barcode.ini.")
    Exit
EndIf
$file = FileRead("temp.ini"); reads temp.txt and assigns the data to $file
    FileOpen("barcode.ini", 2);opens the file in write mode (it will create the file if it doesn't exist)
    $Decrypted_Data = _StringEncrypt (0 , $file, "1234"); decrypts the string "$file" - Tested
    FileWrite("barcode.ini", $Decrypted_Data); writes the data to barcode.ini
    FileClose("barcode.ini");closes the file
_ArrayDisplay($AviList)
While 1 
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
        FileClose(@ScriptDir & "\" & "barcode.ini")
        FileDelete(@ScriptDir & "\" & "barcode.ini")
        Exit
    Case $edit_field
           $user_input = GUICtrlRead($edit_field); sets $user_input to whatever was typed in the edit box
            If IniRead("barcode.ini", "AviCodes", $user_input, "no entry") = "no entry" Then
                MsgBox(16, "Code not found", "The Barcode you entered "&$user_input&" does not have a video.",2)
                WinActivate("Scan Barcode")
                GUICtrlSetData($edit_field, "");erases not successful input
            Else
                $video_file = (@ScriptDir & "\" & IniRead("barcode.ini", "AviCodes", $user_input, "no entry"))
                RunWait (@ProgramFilesDir & "\Windows Media Player\mplayer2.exe /play /fullscreen /close "&$video_file&"")
                WinActivate("Scan Barcode")
                GUICtrlSetData($edit_field, "");erases not successful input
            EndIf
        EndSwitch
        If TimerDiff($timer) > 20000 Then
            _PlayRandom()
        EndIf
WEnd

Func _PlayRandom()
Local $ArrayNumber; first item in the array which is the total number of listed names in the array
Local $RandomArrayNo; The random array number for specifying which video file to play
    $ArrayNumber=$AviList[0]; the [0] specifies the first item in the array
    $RandomArrayNo = Random(2,$ArrayNumber); creates a number between 2 and the number represented by $ArrayNumber
    RunWait (@ProgramFilesDir & "\Windows Media Player\mplayer2.exe /play /fullscreen /close "&$AviList[$RandomArrayNo]&"")
    _PlayRandom()   
EndFunc

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

I am using mplayer2, a stripped down version of windows media player, and with the tags /close and /fullscreen the movie will start to play and immediately go into fullscreen mode and when the movie is finished the media player window closes. I need:

1. The video player window to stay full screen but I need to make the barcode entry ($Edit_Field) the active window so that if someone scans a barcode during the movie that the movie will call the correct video file for the barcode.

I dont require a text window asking for a barcode so that can go if there is a way to make this work this way.

I dont require the video player to be media player either. I would prefer to embed the video control into an autoit controled window. Can I do that?

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...