java 错误声音播放器_java 音频播放器出不了声音,代码里哪有问题啊?
該樓層疑似違規(guī)已被系統(tǒng)折疊?隱藏此樓查看此樓
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;
public class AudioDemo extends JApplet {
private String[] audioFiles={"kiley dean - who will i run to.wma","Lady GaGa - Bad Romance.mp3"};
private JComboBox combFilename=new JComboBox(audioFiles);
private String dirStr="multimedia/";
private AudioClip[] audios;
private AudioClip audioPlay;
private JButton playButton,loopButton,stopButton;
public void init() {
audios=new AudioClip[audioFiles.length];
for(int i=0;i
audios[i]=getAudioClip(getCodeBase(),dirStr+audioFiles[i]);
}
audioPlay=audios[0];
combFilename.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
JComboBox cb=(JComboBox)e.getSource();
int i=cb.getSelectedIndex();
audioPlay=audios[i];
}
});
playButton=new JButton("play");
playButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
audioPlay.play();
stopButton.setEnabled(true);
}
});
loopButton=new JButton("circulate");
loopButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
audioPlay.loop();
loopButton.setEnabled(false);
stopButton.setEnabled(true);
}
});
stopButton=new JButton("stop");
stopButton.setEnabled(false);
stopButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
audioPlay.stop();
loopButton.setEnabled(true);
}
});
JPanel controlPanel=new JPanel();
controlPanel.add(combFilename);
controlPanel.add(playButton);
controlPanel.add(loopButton);
controlPanel.add(stopButton);
setLayout(new BorderLayout());
add(controlPanel,BorderLayout.CENTER);
}
public void stop() {
audioPlay.stop();
}
}
總結(jié)
以上是生活随笔為你收集整理的java 错误声音播放器_java 音频播放器出不了声音,代码里哪有问题啊?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 新款大众高尔夫 R 卸去伪装:前大灯更小
- 下一篇: vivo Y36 手机发布:天玑 602