View Single Post
  #1 (permalink)  
Old 07-24-2007, 02:42 AM
lenny lenny is offline
Member
 
Join Date: Jul 2007
Posts: 40
lenny is on a distinguished road
Make sound play in a java application
Hi, I am developing a GUI that demonstrates the use of many of the JFrame, JPanel, etc components.
One part of the program I want to be a music player, where you press a button to open a file chooser, choose a song, and it plays. Here is the code for the buttonlistener:
Code:
private class ButtonListener implements ActionListener { public void actionPerformed (ActionEvent event) { JFileChooser chooser = new JFileChooser(); int status = chooser.showOpenDialog(null); if (status != JFileChooser.APPROVE_OPTION) song1.setText("No File Yet Chosen"); else { File file = chooser.getSelectedFile(); AudioClip song; try{ song=JApplet.newAudioClip(file.toURL()); song.play(); } catch(Exception e) { e.getMessage(); } } }
My problem is that the music doesn't play. I've tried a variety of techniques that were supposed to make sound play in a java application, but none of them have worked.
The program compiles, but when I click on the button, so sound comes out (even if I choose a .wav file from the file chooser).
Thanks
Reply With Quote
Sponsored Links