Sign in to follow this  
Followers 0
AutID

AutoIt function call practice

16 posts in this topic

#1 ·  Posted (edited)

Hello,

Is this a good way to restart a function in the middle while it is running

Example:

_MyFunc()

While 1
;Do some stuff
If @error Then
Call("_MyFunc")
Return
EndIf
;do some other stuff
WEnd









Edit: Editted because i submitted it before ending by mistake

Edited by AutID

Share this post


Link to post
Share on other sites



AutID,

Most emphatically "NOT". Look at the Recursion tutorial in the Wiki to understand why. But do ask again if you are still unsure. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I wouldn't let it do an infinity loop. If I was to use it I would set a meter and exit after 3-4 times ;)

I am facing a problem with _SoundPlay and _SoundStatus function.

My function check for a path and if the path exists, I have a while loop for _SoundPlay which will ExitLoop after some seconds and an other while loop which will check _SoundStatus and so some things.

These functions throw me an error without reason so I wanted to restart these 2 while loop in my function since the path of the mp3 is correct.

I will try to make a reproducer as soon as I get home from work to explain this better

Edited by AutID

Share this post


Link to post
Share on other sites

AutID,

A reproducer would be helpful. I am listening to my MP3 player at the moment which uses these 2 functions with no problem at all. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

M23,

I added comments so you can understand easier.

Func _MyFunc()
 ;do some cool stuff here
 
 While $aTitle = $sTitle ;This will exit after 30 secs.
  $1 += 1
  If $1 = 1 Then
   $Path = $dlFolder & "\" & $oSong & ".mp3" ;This is the path. Example: C:\Users\FreeMason\Desktop\Playlist\Sting.mp3
   $sSound = _SoundOpen($Path)           ;Even if the path is correct _SoundOpen will throw me error 1
   If @error Then ConsoleWrite("_SoundOpen Error: " & @error & @LF)
   _SoundPlay($sSound)              ;and _SoundPlay throws me error 3
   If @error Then ConsoleWrite("_SoundPlay Error: " & @error & @LF)
  EndIf
 WEnd
 
 $1 = 0
 
 While _SoundStatus($sSound) <> "stopped" ;This will throw me an error that the $var is used before being declared. Since the _SoundOpen and _SoundPlay will return error
  Sleep(1000)
  For $X = 1 To $songs[0][0]
   If WinGetTitle("my window") <> $songs[$X][1] Then
    Do       ;Will sleep until the mp3 ends.
     Sleep(1000)
     ToolTip("Ending in: " & StringTrimRight(_SoundLength($sSound, 2), 3) - StringTrimRight(_SoundPos($sSound, 2), 3) & " seconds", $_X, $_Y)
    Until _SoundStatus($sSound) = "stopped"
    ExitLoop
   EndIf
  Next
 WEnd
 ;do some cool stuff here
EndFunc

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

An error check of winmm.dll will return me this as extended

Edit: Of course when i run the mp3 manually it will play...

Error Number: 10
Error Description: There is a problem with the device driver.  The driver has closed.  Cannot access error.





Edited by AutID

Share this post


Link to post
Share on other sites

AutID,

Whenever I have seen that error reported in other threads it usually turns out to be corrupted ID3 tags which caused the problem and just as in your case the file can often be played in other players. Does this happen with other files or just this one? :huh:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

AutID,

Whenever I have seen that error reported in other threads it usually turns out to be corrupted ID3 tags which caused the problem and just as in your case the file can often be played in other players. Does this happen with other files or just this one? :huh:

M23

I download mp3 and then play them. Some of them can play, others, like this one, can't.

Edit: i use inetget to download them and as i already told you, they play if i play them manually via media player

Edited by AutID

Share this post


Link to post
Share on other sites

AutID,

Then I suggest you clean up the ID3 tags on those files. I recommend stripping them clean and then rewriting the tags - I do that to any files that I did not rip myself. Once you can open and play them properly you will not need those awful loops in your script. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

AutID,

Then I suggest you clean up the ID3 tags on those files. I recommend stripping them clean and then rewriting the tags - I do that to any files that I did not rip myself. Once you can open and play them properly you will not need those awful loops in your script. ;)

M23

I will always be needing those awful loops in my script since i want to do some stuff while the mp3 is playing ;)

How do i remove id3 tags and rewrite them? I searched a little bit a found an ID3 UDF. I ran the gui but i have no clue on how to remove the id3 tags and then rewrite them.

Edit: I also found a small sniper from Xenobiologist: '?do=embed' frameborder='0' data-embedContent>>

but it doesnt return an array for me so it seems it fails to get teh id3 tags

Edited by AutID

Share this post


Link to post
Share on other sites

AutID,

Personally I use TagScanner to do all my ID3 tag work - very reliable and well featured, plus it is free. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

M23,

I did it. Added all ID3 tags and when i check the tags now it returns me all the tags.
However this was not the solution since the problem remains with _SoundOpen.

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

AutID,

My suggestion was to strip all the ID3 tags, save the "naked" .mp3 file and see if it opens, then rewrite the tags on the clean file. ;)

That has always worked up until now - if the file still refuses to open then I am all out of ideas, sorry. :(

M23

P.S. I remember now that it was the album art tags in particular that often caused problems. ;)

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

AutID,

My suggestion was to strip all the ID3 tags, save the "naked" .mp3 file and see if it opens, then rewrite the tags on the clean file. ;)

That has always worked up until now - if the file still refuses to open then I am all out of ideas, sorry. :(

M23

P.S. I remember now that it was the album art tags in particular that often caused problems. ;)

I did it but still.

I came up with a solution.

I created this download function which allowes me to play the files.

Func _FileDownload($sUrl, $SavePath)
 If FileExists($SavePath) Then FileDelete($SavePath) ; So it won't crash since it is not pure autoit
 Local $xml, $Stream
 $xml = ObjCreate("Microsoft.XMLHTTP")
 $Stream = ObjCreate("Adodb.Stream")
 $xml.Open("GET", $sUrl, 0)
 $xml.Send
 $Stream.Type = 1
 $Stream.Open
 $Stream.write($xml.ResponseBody)
 $Stream.SaveToFile($SavePath)
 $Stream.Close
EndFunc
 

Share this post


Link to post
Share on other sites

You could try using the BASS UDF functions, I've not had any problems with using it yet. It also has the possibility of playing more file types.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

You could try using the BASS UDF functions, I've not had any problems with using it yet. It also has the possibility of playing more file types.

It has the possibility to download as well?

I will definitely take that a shot. I always had bass udf but i never thought of it. Never used it.

Good point BrewManNH.

Edit:

Thank you brother. That really solved my hands.

More than 10 tests and all of them succesfully worked.

And who knows, maybe we will someday meet each other ;)

Edited by AutID

Share this post


Link to post
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
Sign in to follow this  
Followers 0