demandnothing Posted October 20, 2009 Share Posted October 20, 2009 (edited) i've been trying to figure out how to do a loop in a function for a music player.. the function is Func play() While $linenumber < _FileCountLines($playlistpath) $Line = FileReadLine($playlistpath, $linenumber) FileDelete($songlistpath) _FileCreate($songlistpath) FileWrite($songlistpath, $Line & @CRLF) $Snd = SoundPlay($Line) $h = _SoundPos($Snd, 2) $i = _SoundLength($Snd, 2) If $h = $i Then $linenumber = $linenumber + 1 EndIf WEnd EndFunc ;==>play what i added was $Snd $h and $i, so that it'll wait for the song to finish before going to the next song.. which it seems like it should work, but i get an array error from Sound.au3.. it says exactly this: C:\Program Files\AutoIt3\Include\Sound.au3 (442) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: If $aSndID[1] <> 0 Then If ^ ERROR ->20:43:40 AutoIT3.exe ended.rc:1 which points to _SoundPos function in the au3 file: Func _SoundPos($aSndID, $iMode = 1) ;Declare variables Local $iSndPosMs, $iSndPosMin, $iSndPosHour, $iSndPosSecs, $sSndPosFormat, $vTemp ;validate $iMode If $iMode <> 1 And $iMode <> 2 Then Return SetError(1, 0, 0) If Not IsArray($aSndID) Then If Not FileExists($aSndID) Then Return SetError(3, 0, 0) ; invalid file/alias $vTemp = FileGetShortName($aSndID) Dim $aSndID[1] = [$vTemp] EndIf If StringInStr($aSndID[0], '!') Then Return SetError(3, 0, 0) ; invalid file/alias ;tell mci to use time in milliseconds __mciSendString("set " & $aSndID[0] & " time format miliseconds") ;receive position of sound $iSndPosMs = Number(__mciSendString("status " & $aSndID[0] & " position", 255)) If $aSndID[1] <> 0 Then $iSndPosMs -= $aSndID[2] EndIf ;modify data and assign to variables _TicksToTime($iSndPosMs, $iSndPosHour, $iSndPosMin, $iSndPosSecs) ;assign formatted data to $sSndPosFormat $sSndPosFormat = StringFormat("%02i:%02i:%02i", $iSndPosHour, $iSndPosMin, $iSndPosSecs) ;return correct variable If $iMode = 1 Then Return $sSndPosFormat If $iMode = 2 Then Return $iSndPosMs EndFunc ;==>_SoundPos specifically: ;receive position of sound $iSndPosMs = Number(__mciSendString("status " & $aSndID[0] & " position", 255)) If $aSndID[1] <> 0 Then $iSndPosMs -= $aSndID[2] EndIf i've never opened (let alone edited) Sound.au3 before this error occured Edited October 20, 2009 by demandnothing Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted October 20, 2009 Share Posted October 20, 2009 Look at what _SoundPlay() returns, it's just 1 for success or 0 for failure so of course you can't use _SoundPos() with that! You are supposed to use the return value from _SoundOpen() in _SoundPos(). Check all of these functions in the helpfile and it will be clear how you should do. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
demandnothing Posted October 20, 2009 Author Share Posted October 20, 2009 (edited) according to the functions list SoundPlay returns 1 with success or failure Func play() While $linenumber < _FileCountLines($playlistpath) ;Change the number to however many songs youre gonna have in your playlist $Line = FileReadLine($playlistpath, $linenumber) FileDelete($songlistpath) _FileCreate($songlistpath) FileWrite($songlistpath, $Line & @CRLF) $aSnd = _SoundOpen($Line) $h = _SoundPos($aSnd, 2) $i = _SoundLength($aSnd, 2) If $h = $i Then $linenumber = $linenumber + 1 EndIf WEnd EndFunc ;==>play fails.. no buttons work.. i dont get the error but it doesnt work Func play() While $linenumber < _FileCountLines($playlistpath) ;Change the number to however many songs youre gonna have in your playlist $Line = FileReadLine($playlistpath, $linenumber) FileDelete($songlistpath) _FileCreate($songlistpath) FileWrite($songlistpath, $Line & @CRLF) $aSnd = _SoundOpen($Line) $Snd = _SoundPlay($aSnd) $h = _SoundPos($Snd, 2) $i = _SoundLength($Snd, 2) If $h = $i Then $linenumber = $linenumber + 1 EndIf WEnd EndFunc ;==>play gives me the same error.. but its not the same as SoundPlay, its _SoundPlay lol edit: compliments on your music player.. very nice.. glad to have you helping me Edited October 20, 2009 by demandnothing 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