此SSCCE在这里是“无效结果”,因为音频无例外地重新启动(尝试至少3次)。
import java.net.URL;import java.awt.event.*;import javax.swing.*;import javax.sound.sampled.*;public class RestartableLoopSound { public static void main(String[] args) throws Exception { URL url = new URL( "http://pspre.org/media/leftright.wav"); final Clip clip = AudioSystem.getClip(); AudioInputStream ais = AudioSystem. getAudioInputStream( url ); clip.open(ais); SwingUtilities.invokeLater(new Runnable() { public void run() { final JToggleButton b = new JToggleButton("Loop"); ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent ae) { if (b.isSelected()) { // loop continuously clip.loop(Clip.LOOP_CONTINUOUSLY); } else { clip.stop(); } } }; b.addActionListener(listener); JOptionPane.showMessageDialog(null, b); } }); }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)