Sign in to follow this  
Followers 0
Didonet

while in the while... or what?

8 posts in this topic

#1 ·  Posted (edited)

Hello again. I have problem with the while 1 that is for the main functions and actions.

How can I create a loop in that loop, but when I start the loop I don't want the program to "freeze" and action only the thing in this loop. I want to work everything else when the loop is started. Is it possible?

In other words:

I'm creating a mp3 player. When I start the song I use that to show me the time:

While 1
            GUICtrlSetData($currentTime, _SoundPos($sound, 1))
            If _SoundPos($sound, 2) = _SoundLength($sound, 2) Then ExitLoop
            Sleep(950)
    WEnd

but when it's in the main loop everything else freeze and i can't do anything...

Edited by Didonet

Share this post


Link to post
Share on other sites



Well.. of course, you can't do that. But you can do it in different ways... for example, use only one main loop where you call a function that does what you want

While 1
    Myfunc()
    Sleep(950)
;Rest of the script..
WEnd

Func Myfunc()
    GUICtrlSetData($currentTime, _SoundPos($sound, 1))
    If _SoundPos($sound, 2) = _SoundLength($sound, 2) Then ExitLoop
EndFunc  ;==>Myfunc

Maybe you can also take a look at AdlibEnable()

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

That's the part of the main while:

While 1

    $msg = GUIGetMsg()

; Some code

    If $msg = $playButton Then
        Play($file)
        While 1
            GUICtrlSetData($currentTime, _SoundPos($sound, 1))
            If _SoundPos($sound, 2) = _SoundLength($sound, 2) Then ExitLoop
            Sleep(950)
        WEnd
    EndIf


; Some code

Wend

Where what to put? :blush:

Edited by Didonet

Share this post


Link to post
Share on other sites

Something like this..

While 1

    $msg = GUIGetMsg()

; Some code

    If $msg = $playButton Then
        Play($file)
        Myfunc()
        Sleep(950)
    EndIf


; Some code

Wend

Func Myfunc()
    GUICtrlSetData($currentTime, _SoundPos($sound, 1))
EndFunc  ;==>Myfunc

But you adapt it to your needs, that might now work for you. It was just an idea.

Share this post


Link to post
Share on other sites

Yea, this works, but it refresh the time only once. If i put a loop everything "freezes" again... <_<

Share this post


Link to post
Share on other sites

Maybe like this??

While 1
    $msg = GUIGetMsg()

    ; Some code

    If $msg = $playButton Then
        Play($file)
        $Play = 1
    EndIf
    If $Play = 1
        GUICtrlSetData($currentTime, _SoundPos($sound, 1))
    EndIf

    ; Some code

Wend

Share this post


Link to post
Share on other sites

Yes! That's great! <_<

But when Play = 1 the GuiCtrlSetData is very fast and the process of the player is 50%>

If I set a sleep after the GuiCtrlSetData something goes wrong...

Share this post


Link to post
Share on other sites

Yes! That's great! <_<

But when Play = 1 the GuiCtrlSetData is very fast and the process of the player is 50%>

If I set a sleep after the GuiCtrlSetData something goes wrong...

Maybe this is better then??

$SlowerPositions = 1

While 1
    $msg = GUIGetMsg()
    
    ; Some code
    
    If $msg = $playButton Then
        Play($file)
        $Play = 1
    EndIf
    If $Play = 1 And $SlowerPositions > 50 Then
        GUICtrlSetData($currentTime, _SoundPos($sound, 1))
        $SlowerPositions = 1
    EndIf
    $SlowerPositions = $SlowerPositions + 1
    
    ; Some code
    
Wend

(If you want it go slower you increase 50)

But then the updatingspeed would be dependent on the CPU.... Maybe you should think about using an Adlib instead??

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