Getting sound position can end a sound

  • If you play a sound and immediately start a loop checking the play position, say for a progress indicator, you can "crash" or end the sound, actually firing the oncomplete event. to wit:

    Code
    playsound(test);
    getposition();
    
    
    <action name="getposition">
         copy(sposition, sound[test].position);
         delayedcall(0.3,getposition());
    </action>


    If the sound isn't fully loaded you get "[object][object]" as the "position" and the loop continues. No foul. But try the above after the sound has played and you get a position of "0" which isn't possible once the sound has started to play. Problem is, the sound then ends before it starts and fires the oncomplete event. Not what you want.

    My kludgy workaround is to delay starting the loop, giving the sound time to actually start before getting its position. I say kludgy because if you don't wait long enough -- perhaps if something unexpectedly delays the sound starting to play -- I suspect you could still have the problem.

    Klaus -- Could the soundinterface code be changed to avoid this issue?

    Anyway, whether this is a bug that can be fixed or a fact of life we have to live with, perhaps this post can help someone else avoid the hours it took me to run this down. Just keep telling yourself, "Coding is fun!"

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!