尝试转换为频谱,但首先我需要播放音乐,但是当我点击按钮“无法创建音频数据对象”时,我需要一些帮助来完成我的项目。
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);
}
}