Tag: clip

剪辑有时不播放

我有一个Sound类,其中包含一个方法,当调用该方法时,使用Clip对象(在本例中为clip )播放声音。 public static void play() { clip.stop(); // The purpose of the first three lines clip.flush(); // is to restart the Clip object so it clip.setFramePosition(0); // can be played multiple times. clip.start(); } Clip对象的实例化发生在一个单独的静态方法中,该方法在此方法之前调用,这就是上述方法可以声明为静态的原因。 另一个实现KeyListener类包含以下代码: public void keyPressed(KeyEvent e) { Sound.play(); // Sound is the class that implements the previous method. } 因此,每按一次键,我的代码应播放与clip相关的声音。 […]