Salve. Come posso riprodurre dei file audio in java? Ho questo esempio funzionante ma è valido solo per le applet, ma io vorrei sapere come fare per riprodurre audio in un'applicazione normale con JFrame...
codice:import java.applet.AudioClip; import java.awt.event.ItemListener; import java.awt.event.ItemEvent; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.FlowLayout; import javax.swing.JApplet; import javax.swing.JButton; import javax.swing.JComboBox; public class Sound extends JApplet { private AudioClip sound1, sound2, currentSound; private JButton play, loop, stop; private JComboBox sound; public void init() { setLayout (new FlowLayout()); String[] choices = {"Suono 1", "Suono 2"}; sound = new JComboBox (choices); sound.addItemListener ( new ItemListener() { public void itemStateChanged (ItemEvent event) { currentSound.stop(); currentSound = sound.getSelectedIndex() == 0 ? sound1 : sound2; } } ); add (sound); ButtonHandler handler = new ButtonHandler(); play = new JButton ("Play"); play.addActionListener (handler); add (play); loop = new JButton ("Loop"); loop.addActionListener (handler); add (loop); stop = new JButton ("Stop"); stop.addActionListener (handler); add (stop); sound1 = getAudioClip (getDocumentBase(), "bu.wav"); sound2 = getAudioClip (getDocumentBase(), "miami69.wav"); currentSound = sound1; } public void stop() { currentSound.stop(); } private class ButtonHandler implements ActionListener { public void actionPerformed (ActionEvent event) { if (event.getSource() == play) currentSound.play(); else if (event.getSource() == loop) currentSound.loop(); else if (event.getSource() == stop) currentSound.stop(); } } }

