Trying to convert into spectrum but first I needed to play music but when I clicked the button "could not create audio data object" appears so I needed some help for my project.
package sounds;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import java.io.*;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;
import sun.audio.*;
import javax.swing.JButton;
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.*;
public class Frame {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
AudioPlayer MGP;
AudioStream BGM;
AudioData MD;
Frame window = new Frame();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Frame() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton btnNewButton = new JButton("New button");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
AudioPlayer MGP = AudioPlayer.player;
AudioStream BGM;
AudioData MD;
ContinuousAudioDataStream loop=null;
try{
BGM =new AudioStream(new FileInputStream("georgia.wav"));
MD=BGM.getData();
loop = new ContinuousAudioDataStream (MD);
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
MGP.start(loop);
}
});
frame.getContentPane().add(btnNewButton, BorderLayout.WEST);
}
}