Is there any way to measure or get the length of a selected sound?


// add the instance field private long soundStartTime; // also, you should have GreenfootSound sound = new GreenfootSound("nameOfFile.wav"); // the rest is in the 'act' method // to begin the sound (press any key) if (soundStartTime == 0 && Greenfoot.getKey() != null) { sound.play(); soundStartTime = System.currentTimeMillis(); } // to check for sound stopping if (soundStartTime != 0 && !sound.isPlaying()) { long elapsedTime = System.currentTimeMillis()-soundStartTime; System.out.println("The sound took "+(elapsedTime/1000)+" seconds to play."); soundStartTime = 0; }
// just add the instance field to hold the length in milliseconds private long soundLength = 4263;