当我尝试在小程序中同时播放两个声音时,它将不起作用。我正在使用AudioClips。甚至可以在小程序中同时播放两个声音吗?
AudioClip
从Java 1.3+开始,请使用ClipJava Sound API 的类。它类似于基于applet的AudioClip类,但更好。
Clip
EG改编自Java声音信息上显示的EG。
import java.net.URL; import javax.swing.*; import javax.sound.sampled.*; public class LoopSounds { public static void main(String[] args) throws Exception { URL url = new URL( "http://pscode.org/media/leftright.wav"); Clip clip = AudioSystem.getClip(); AudioInputStream ais = AudioSystem. getAudioInputStream( url ); clip.open(ais); URL url2 = new URL( "http://pscode.org/media/100_2817-linear.wav"); Clip clip2 = AudioSystem.getClip(); AudioInputStream ais2 = AudioSystem. getAudioInputStream( url2 ); clip2.open(ais2); // loop continuously clip.loop(Clip.LOOP_CONTINUOUSLY); clip2.loop(Clip.LOOP_CONTINUOUSLY); SwingUtilities.invokeLater(new Runnable() { public void run() { // A GUI element to prevent the Clip's daemon Thread // from terminating at the end of the main() JOptionPane.showMessageDialog(null, "Close to exit!"); } }); } }