0

I'm having problems with java not correctly waiting for a method to finish before continueing. I have a sound file that lasts an unknown amount of time and I want to set lengthS to that time, I do this by taking the System's current time in milliseconds before and after I play the sound and taking the difference. However for some reason it does not wait for the sound to finish playing before continuing and lengthS ends up at about 100ms, not 2000ms as it should be.

repaint();
            t0=System.currentTimeMillis();
            AudioClip a = getAudioClip(getDocumentBase(), file[counter]);
            a.play();
            t1=System.currentTimeMillis();
            lengthS=(t1-t0);
            texts="2"; repaint();
            record(lengthS);
            texts="3"; repaint();
            a.play();
            texts="4";repaint();
            playback();
            texts="5";repaint();
            counter++;
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by quuba
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.