首页 文章

通过Clip和AudioInputStream重放Java声音不起作用

提问于
浏览
0

这是Java声音信息页面中略微修改的示例 . https://stackoverflow.com/tags/javasound/info不幸的是,它只播放一次声音但意图是两次 .

import java.io.File;
import javax.sound.sampled.*;

public class TestNoise {
    public static void main(String[] args) throws Exception {
        File f = new File("/home/brian/drip.wav");
        AudioInputStream ais = AudioSystem.getAudioInputStream(f);

        AudioFormat af = ais.getFormat();
        DataLine.Info info = new DataLine.Info(Clip.class, af);
        Clip clip = (Clip)AudioSystem.getLine(info);

        clip.open(ais);
        clip.start();    // heard this
        Java.killTime(); 
        clip.start();    // NOT HEARD
        Java.killTime();
    }
}

Edit: To understand the answer, see the link provided by Wanderlust or just do what it says in the comment below his answer.

1 回答

  • 0

    要第二次播放剪辑,您必须拨打电话

    clip.start();
    clip.stop();
    

    在第二次调用clip.start()之后导致它试图从it stopped previously的地方播放文件 .

相关问题