简体   繁体   中英

set time interval between repeating audio clip in java when using clip.loop(Clip.LOOP_CONTINUOUSLY);

I am trying to loop a small ".wav" audio file. The code I used worked perfectly but I want to set some time interval between looping audio. Code is provided below.

    try {
        // from a wave File
        File soundFile = new File("path");
        AudioInputStream audioIn = AudioSystem.getAudioInputStream(soundFile);

        clip = AudioSystem.getClip();

        clip.open(audioIn);
        clip.loop(Clip.LOOP_CONTINUOUSLY); //IS THERE ANY WAY TO CREATE TIME INTERVAL???

            } catch (Exception e) {
        JOptionPane.showMessageDialog(null,
                "Hi. This is background music error \n" + e);
    }
while (playing)
{
  yourBeepClip.setFramePosition(0);
  yourBeepClip.start();
  Thread.sleep(pauseAmount);
}

The Clip is only instantiated & opened ONE TIME.

Also, the above while loop is assumed to be occurring in its own thread.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM